问题描述
我在 PFQueryTableViewController 的顶部添加了一个 UISearchBar.我已将 searchBar 的颜色更改为我的应用程序的颜色,但在这样做时,它似乎也将其右侧的"取消"按钮的颜色更改为相同的颜色.理想情况下,我希望颜色为白色.
这张图片显示了它目前的样子:
看起来没有"取消"按钮,但有,它与搜索栏颜色相同(您仍然可以按下它等)
有没有办法让我将此"取消"按钮的颜色更改为白色?我尝试过的一切似乎都没有区别.
我用来制作 UISearchBar 这种颜色的代码是:
UISearchBar.appearance().barTintColor = UIColor(hue: 359/360, saturation: 67/100, brightness: 71/100, alpha: 1) UISearchBar.appearance().tintColor = UIColor(hue: 359/360, saturation: 67/100, brightness: 71/100, alpha: 1)
在情节提要中我设置了这些:
最后,为了使占位符和 SearchBar 内的文本变为白色,我使用了:
for subView in self.filmSearchBar.subviews { for subsubView in subView.subviews { if let searchBarTextField = subsubView as? UITextField { searchBarTextField.attributedPlaceholder = NSAttributedString(string: NSLocalizedString("Search Cinevu film reviews", comment: ""), attributes: [NSForegroundColorAttributeName: UIColor.whiteColor()]) searchBarTextField.textColor = UIColor.whiteColor() } } }
感谢您的帮助!:)
推荐答案
环顾四周,这似乎是实现我所需要的最佳方式:
let cancelButtonAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white] UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes , for: .normal)