Swift 从UISearchBar更改UIBarbuttonite
我想在iOS 8中更改UI搜索栏中“取消”按钮的文本字体和颜色。我已经尝试过iOS 6和iOS 7的解决方案,但它们似乎不起作用。这不是我想要的解决方案,但它起了作用Swift 从UISearchBar更改UIBarbuttonite,swift,ios8,uisearchbar,uibarbuttonitem,uicolor,Swift,Ios8,Uisearchbar,Uibarbuttonitem,Uicolor,我想在iOS 8中更改UI搜索栏中“取消”按钮的文本字体和颜色。我已经尝试过iOS 6和iOS 7的解决方案,但它们似乎不起作用。这不是我想要的解决方案,但它起了作用 let cancelButtonAttributes: NSDictionary = [NSFontAttributeName: FONT_REGULAR_16!, NSForegroundColorAttributeName: COLOR_BLUE] UIBarButtonItem.appearance().setTitleTe
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()
你能告诉我们你试过什么吗?这对我也有用。swift 2的次要修订,删除了字体属性和常量。-让cancelButtonAttributes:NSDictionary=[NSForegroundColorAttributeName:UIColor.blackColor()]UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes as?[String:AnyObject],forState:UIControlState.Normal)这会更改所有栏按钮项的颜色,而不仅仅是UISearchBar的Cancel按钮。