【发布时间】:2015-01-08 10:37:30
【问题描述】:
我想更改 iOS 8 中 UISearchBar 内取消按钮的文本字体和颜色。我已经尝试了 iOS 6 和 7 的解决方案,但它们似乎不起作用。
【问题讨论】:
-
你能告诉我们你的尝试吗?
标签: swift ios8 uisearchbar uibarbuttonitem uicolor
我想更改 iOS 8 中 UISearchBar 内取消按钮的文本字体和颜色。我已经尝试了 iOS 6 和 7 的解决方案,但它们似乎不起作用。
【问题讨论】:
标签: swift ios8 uisearchbar uibarbuttonitem uicolor
这不是我想要的解决方案,但它确实有效。
let cancelButtonAttributes: NSDictionary = [NSFontAttributeName: FONT_REGULAR_16!, NSForegroundColorAttributeName: COLOR_BLUE]
UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, forState: UIControlState.Normal)
【讨论】:
你要找的是:
//The tintColor below will change the colour of the cancel button
searchBar.tintColor = UIColor.blueColor()
但是当我们讨论这个主题时,这些也很有用:
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()
【讨论】: