views:

54

answers:

1

Hi all,

I have implemented a custom UINavigationbar using this code (placed in the top of my AppDelegate.m file):

@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
    UIImage *image = [UIImage imageNamed: @"NavigationBar.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end

And it works great! The problem is, when I push a particular class of view controller, I would like to remove the custom navigationbar and show the standard one (or alternatively change the NavigationBar.png).

But I can't figure out how to do this, and googling isn't really helping. Has anyone done this?

Many thanks, Brett

A: 

Rather than use the drawRect override, place this bit of code in each view controller inside the navigation controller. Then just change the image that is used in each view controller you want it to be different:

    self.navigationController.navigationBar.layer.contents = (id)[UIImage imageNamed:@"NavigationBar.png"].CGImage;

You will have to include Quartz core, so include this line in the imports of your view controllers header file:

#import <QuartzCore/QuartzCore.h>
Andy Smart
Hmmm...compiles fine. However, NavigationBar.png isn't displayed. It still shows the original NavigationBar. I put this in my loadView method. Would you suggest calling it somewhere else?
Brett
Thats odd, always seems to work fine for me in loadView. You will have to remove your UINavigationBar (CustomImage) drawRect function in your App Delegate for it to work though, is that still there?
Andy Smart
Yes I did remove it. There is probably something else going on. I am using Three20, so I am sure that is messing things up. I like the logic of your answer, so I'll continue to try to work around any Three20 issues and get that to work. Many thanks.
Brett