Change UIBarButtonItem from UISearchBar

后端 未结 2 383
醉梦人生
醉梦人生 2020-12-12 02:48

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 w

相关标签:
2条回答
  • 2020-12-12 03:05

    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()
    
    0 讨论(0)
  • 2020-12-12 03:07

    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)
    
    0 讨论(0)
提交回复
热议问题