开发者

change 3 navigation bar background with different image

开发者 https://www.devze.com 2023-01-28 17:26 出处:网络
i have 3 navigation controller and i want to change each background using different image. I was implement a category that extends UINavigationBar like this :

i have 3 navigation controller and i want to change each background using different image. I was implement a category that extends UINavigationBar like this :

- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed:@"backgr开发者_开发问答ound.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];} 

@end

but it make every navigation bar have a same background image. And then i try to implement code like this :

- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
UIImageView *backGroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
[self.navigationController.navigationBar insertSubview:backGroundView atIndex:0];
[backGroundView release];

}

in every controller but each background just show the tintColor, not the image...what should I do???

and how if i want to do that too in tabbarController??


On each of your views, implement the following in your viewWillAppear: method

#import <QuartzCore/QuartzCore.h>
...

- (void)viewWillAppear:(BOOL)animated 
{
     self.navigationController.navigationBar.layer.contents = (id)[UIImage imageNamed:@"yourImageBgHere"].CGImage;
}

Cheers, Rog

0

精彩评论

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