UISearchbar添加navigationController?.navigationBar。如何更改"取消"颜色
(validation with select command)
此结果为"取消"颜色是白色的。如何将其设置为红色?
答案 0 :(得分:0)
让cancelButtonAttributes: NSDictionary = [NSForegroundColorAttributeName: ``UIColor.YOUR COLOR]
UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes as?
[String : AnyObject], forState: UIControlState.Normal)
答案 1 :(得分:0)
使用appearance
模块的UIAppearance
功能 -
方法1: - 加载searchBar
时可见的取消按钮颜色 -
let attributes = [NSForegroundColorAttributeName : UIColor.red]
UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).setTitleTextAttributes(attributes, for: .normal)
或 -
方法2: -
searchBar
点击后可见取消按钮颜色 -
UIBarButtonItem.appearance(whenContainedInInstancesOf:[UISearchBar.self]).tintColor = UIColor.red
答案 2 :(得分:0)
将格式更改为可读性
let cancelButtonAttributes: NSDictionary = [NSForegroundColorAttributeName: UIColor.YOUR COLOR] UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes as? [String : AnyObject], forState: UIControlState.Normal)