尝试将这些代码中的任何一个放入ViewWillAppear/ViewDidAppear/didFinishLaunchingWithOptions
(在 appDelegate 的情况下)。
1)navigationItem.titleView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"urtitlebar.png"]];
或者
2)
UIView *myView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"urtitlebar.png"]];
[image setFrame:CGRectMake(0, 0, 44, 44)];
[myView addSubview:image];
[self.navigationController.navigationBar addSubview:myView];
或者
3)
UINavigationBar *navBar = self.navigationController.navigationBar;
UIImage *image = [UIImage imageNamed:@"urtitlebar.png"];
[navBar setBackgroundImage:image];
编辑:(如果你使用旧版本的 SDK 说 3.2.5)
创建子视图UINavigationBar
并覆盖调用的方法 -drawRect:(CGRect)rect
与,
@implementation UINavigationBar (BackgroundImage)
- (void)drawRect:(CGRect)rect
{
UIImage *navBarImage;
image = [UIImage imageNamed: @"urNavigationBar.png"];
}
[navBarImage drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@结尾