I am using Swift to build an iOS application and would like to change the global appearance
of UIBarButtonItem
. I am doing this in didFinishLaunchingWithOptions
.
Apple's documentation says this:
func setTitleTextAttributes(_ attributes: [String : AnyObject]?, forState state: UIControlState)
for UIBarItem
. But when I try to do this, it only expects self: UIBarItem
. Has anyone else encountered this? Is it a bug in Xcode or am I doing something wrong?
Did you tried realising it with UIAppearance
protocol? It should be used for global сustomizing some visual classes. I can suggest your some code like this:
UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UINavigationBar.classForCoder()]).setTitleTextAttributes(["attribute" : "value"], forState: .Normal)
Hopes it is clear from the code the way in works and how you can enwide it.
Call setTitleTextAttributes
on the UIBarButtonItem
appearance proxy:
Swift 3:
UIBarButtonItem.appearance().setTitleTextAttributes([key : value], for: .normal)
Swift 2.x:
UIBarButtonItem.appearance().setTitleTextAttributes([key : value], forState: UIControlState.Normal)
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