I am using the following code to add a custom navbar to my app. But I want to be able to change the navbar depending on the view, is this possible?
@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect
{
UIColor *color = [UIColor colorWithRed:82/255.0 green:80/255.0 blue:81/255.0 alpha:1.0];
UIImage *img = [UIImage imageNamed: @"navbar.png"];
[img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
self.tintColor = color;
}
@end
If not, is it possible to just add an image to the navbar instead of title text?
I would strongly discourage using a category to override
-drawRecton a UINavBar as this design will break on a soon to be released iOS version.It is very easy to create custom images and buttons to the navBar title though. Here’s some code snippets I pulled directly out of production code for one of my apps. It creates a custom image button in the navBar’s title area, but it’s just as easy to create an image instead:
And this is what the button looks like in the app VideoBot:

Here’s an example of using an image for the navbar title: