开发者

Custom UINavigationbar for different views - iPhone SDK

开发者 https://www.devze.com 2023-01-15 15:37 出处:网络
I have implemented a custom UINavigationbar using this code (placed in the top of my AppDelegate.m file):

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消