I am trying to change the font of the UISearchBar cancel button to 'OpenSans' but I am unable to access any properties. I can only change the tint color of UISearchBar, which changes the color of the search bar cancel button text & search bar UITextField cursor color:
searchBar.tintColor = UIColor(red: 187.0/255.0, green: 187.0/255.0, blue: 187.0/255.0, alpha: 1.0)
Is there a way to accomplish this?
Try something like this it worked for me.
UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).setTitleTextAttributes([NSFontAttributeName : UIFont(name: "OpenSans", size: 15)!], forState: .Normal)
If you want to change the color as well add this to your array of attributes.
NSForegroundColorAttributeName : UIColor.whiteColor()
Note: Made available in iOS 9
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With