Change UIBarButtonItem from UISearchBar

馋奶兔 提交于 2019-11-28 14:11:39

This was not the solution I was looking for, but it worked.

let cancelButtonAttributes: NSDictionary = [NSFontAttributeName: FONT_REGULAR_16!, NSForegroundColorAttributeName: COLOR_BLUE]
UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, forState: UIControlState.Normal)

What you are looking for is:

//The tintColor below will change the colour of the cancel button
searchBar.tintColor = UIColor.blueColor()

But these are also useful While we are on the subject:

searchBar.placeholder = "Placeholder"
//The barTintColor changes the colour of the flashing text indicator
searchBar.barTintColor = UIColor.redColor()
//This sets the cancel button to show up
searchBar.setShowsCancelButton(true, animated: true)
//This makes the searchBar become active 
searchBar.becomeFirstResponder()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!