代码修改如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
_rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];
_nav = [[UINavigationController alloc] initWithRootViewController:_rootViewController];
UIImage *backgroundImage = [UIImage imageNamed:@"NaviBackground.png"];
[self setNavigationBarBackgroundImage:backgroundImage];
[self.window setRootViewController:_nav];
[self.window makeKeyAndVisible];
returnYES;
}
- (void)setNavigationBarBackgroundImage:(UIImage *)backgroundImage
{
UINavigationBar *navBar = [_nav navigationBar];
if ([navBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {
[navBar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
}
else {
UIImageView *imageView = (UIImageView *)[navBar viewWithTag:kSCNavBarImageTag];
if (imageView == nil) {
imageView = [[UIImageView alloc] initWithImage:backgroundImage];
[imageView setTag:kSCNavBarImageTag];
[navBar insertSubview:imageView atIndex:0];
[imageView release];
}
}
}
参考:
Adding a Background Image to UINavigationBar