Change UIBarButtonItem from UISearchBar

我只是一个虾纸丫 提交于 2019-11-27 08:17:01

问题


I'd like to change the text font and color of the Cancel button inside the UISearchBar in iOS 8. I've tried the solutions for iOS 6 and 7 already and they don't seem to work.


回答1:


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)



回答2:


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()


来源:https://stackoverflow.com/questions/27838084/change-uibarbuttonitem-from-uisearchbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!