UISearchbar添加navigationController?.navigationBar,如何更改"取消"颜色

时间:2017-08-14 05:54:23

标签: ios swift uinavigationbar uisearchbar

UISearchbar添加navigationController?.navigationBar。如何更改"取消"颜色

(validation with select command)

此结果为"取消"颜色是白色的。如何将其设置为红色?

3 个答案:

答案 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)