Is there an easy way to change the text color of a UIBarButtonItem without using an UIImage as the background?
By default the text is always white. I'd like to make it black.
Is there an easy way to change the text color of a UIBarButtonItem without using an UIImage as the background?
By default the text is always white. I'd like to make it black.
The direct answer to your question is no.
You can't simply change the color of a
UIBarButtonItem
by setting one of its properties. You can set thetintColor
property of theUIToolBar
orUINavigationBar
that contains theUIBarButtonItem
s, but that also affects the color of the toolbar itself and doesn't offer too much customization.If that doesn't work for you, a custom view as the other answers suggest is a fine idea.
Good luck!
I'd rather use a UIButton inside a UIBarButtonItem and customize that one.
This is an example with custom graphics for a custom UIButton. The idea stays the same use
initWithCustomView
of the UIBarButtonItem to put something else in it which is easily customizable.Thank to IOS 5.0 you do not need to use images for that.You can set various text attributes with following code.
You can set a custom view by using
[[UIBarButtonItem alloc] - (id)initWithCustomView:(UIView *)customView]