更改色调不会更改搜索栏内 "cancel" 按钮的字体
Changing the tint color is not changing the font of the "cancel" button inside the search bar
我有一个名为 SearchView 的 UIView,我正在添加 searchController.searchBar 作为 UIView 的子视图。
在 viewDidLoad() 中,我正在更改 UISearchController 中的搜索栏,如下所示:
//makes background transparent
searchController.searchBar.backgroundImage = UIImage()
//makes magnifying glass white
let iconView:UIImageView = tf!.leftView as! UIImageView
iconView.image = iconView.image?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
iconView.tintColor = UIColor.whiteColor()
//changes text color to white
let tf = searchController.searchBar.valueForKey("searchField") as? UITextField
let attributedString = NSAttributedString(string: "", attributes:[NSForegroundColorAttributeName : UIColor.whiteColor()])
tf!.attributedPlaceholder = attributedString
tf!.textColor = UIColor.whiteColor()
//changes search field background color
tf!.backgroundColor = UIColor(red: 82/255, green: 91/255, blue: 93/255, alpha: 1)
//HERE: should make the cancel button font white...
searchController.searchBar.tintColor = UIColor.whiteColor()
searchView.addSubview(searchController.searchBar)
在 AppDelegate 中,我有
UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).tintColor = UIColor.whiteColor()
在启动时在您的应用委托中这样说:
UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).tintColor = UIColor.whiteColor()
请注意,这仅在搜索栏中正在进行编辑时才会生效。如果搜索栏中没有编辑,则没有可取消的内容,因此“取消”按钮变暗并且没有颜色(它是一种基于 tint 颜色的灰色)。
我有一个名为 SearchView 的 UIView,我正在添加 searchController.searchBar 作为 UIView 的子视图。
在 viewDidLoad() 中,我正在更改 UISearchController 中的搜索栏,如下所示:
//makes background transparent
searchController.searchBar.backgroundImage = UIImage()
//makes magnifying glass white
let iconView:UIImageView = tf!.leftView as! UIImageView
iconView.image = iconView.image?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
iconView.tintColor = UIColor.whiteColor()
//changes text color to white
let tf = searchController.searchBar.valueForKey("searchField") as? UITextField
let attributedString = NSAttributedString(string: "", attributes:[NSForegroundColorAttributeName : UIColor.whiteColor()])
tf!.attributedPlaceholder = attributedString
tf!.textColor = UIColor.whiteColor()
//changes search field background color
tf!.backgroundColor = UIColor(red: 82/255, green: 91/255, blue: 93/255, alpha: 1)
//HERE: should make the cancel button font white...
searchController.searchBar.tintColor = UIColor.whiteColor()
searchView.addSubview(searchController.searchBar)
在 AppDelegate 中,我有
UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).tintColor = UIColor.whiteColor()
在启动时在您的应用委托中这样说:
UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).tintColor = UIColor.whiteColor()
请注意,这仅在搜索栏中正在进行编辑时才会生效。如果搜索栏中没有编辑,则没有可取消的内容,因此“取消”按钮变暗并且没有颜色(它是一种基于 tint 颜色的灰色)。