我有3个导航控制器,我想用不同的图像更改每个背景。我实现了一个扩展UINavigationBar的类别:
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed:@"background.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];}
@end
但它使每个导航栏都有相同的背景图像。然后我尝试实现这样的代码:
- (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];
}
在每个控制器中,但每个背景只显示tintColor,而不是图像......我应该怎么做???
如果我想在tabbarController中做到这一点?
答案 0 :(得分:0)
在每个观看次数中,在viewWillAppear:
方法
#import <QuartzCore/QuartzCore.h>
...
- (void)viewWillAppear:(BOOL)animated
{
self.navigationController.navigationBar.layer.contents = (id)[UIImage imageNamed:@"yourImageBgHere"].CGImage;
}
干杯, ROG