我的应用程序有多个 View Controller ,对于其中一些 View Controller ,我想在将它们推送到导航堆栈时使用不同的导航栏背景图像。
例如,当我的 mainViewController 加载时,我有这个:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(@"Setting toolbar for iOS 5+");
UIImage * navbarImage = [UIImage imageNamed:@"navbar01.png"];
[[UINavigationBar appearance] setBackgroundImage:navbarImage forBarMetrics:UIBarMetricsDefault];
}
同样,当我的另一个 viewController 被推送到导航堆栈时,我使用与上面相同的代码,除了使用不同的 UIImage (navbar02.png)。
但是,导航栏与我设置的第一张图像相比没有变化。当新 View 出现时,有什么方法可以更改 UINavigationBar 背景图像吗?
谢谢!
最佳答案
以下是类似问题的链接:UINavigationBar setBackgroundImage: forBarMetrics: Not Working
答案是使用这个:
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
而不是您使用过的代码。
关于iphone - 在 iOS 5 中为 UINavigationBar 设置不同的背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10099663/