I'd like to change the background of my UINavigationBar to a [UIColor colorWithImage:]
, but it isn't working. What am I missing?
EDIT:
Once I've created my subclass, where do I set the UINavigationController to use it?
I'd like to change the background of my UINavigationBar to a [UIColor colorWithImage:]
, but it isn't working. What am I missing?
EDIT:
Once I've created my subclass, where do I set the UINavigationController to use it?
You can use the
tintColor
property to change the colour of aUINavigationBar
, but to set an image as the background you'll have to provide your ownUINavigationBar
subclass and override thedrawRect:
method, for example:If you use Interface Builder to build your UI then to use the custom navigation bar, just select the UINavigationBar element in Interface Builder, open the Inspector and in the Identity tab specify your UINavigationBar subclass in the class field, like so:
To have an image in the navigation bar, you have to draw it yourself, which actually isn't that hard. Save this as
UINavigationBar+CustomBackground.m
(it adds a custom category to UINavigationBar):