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 g开发者_如何学运维reat! 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
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>
精彩评论