自从我更新到 xcode 4.2 和 iOS 5 后,以下代码无效:
@implementation UINavigationBar (CustomNavBarBG)
-(void)drawRect:(CGRect)rect{
UIImage *image = [UIImage imageNamed:@"navbar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
self.tintColor = [UIColor colorWithRed:124/255.0 green:177/255.0 blue:55/255.0 alpha:1.0];
}
@end
@implementation MyAppDelegate
//....
这应该将背景图像和颜色应用于导航栏。但是自更新以来,我得到了默认的蓝色。我在我的项目中使用 three20 框架。
知道为什么这不起作用吗?如何在一个地方而不是在每个 View Controller 中为所有导航栏设置背景图像?
最佳答案
尝试设置:
[[UINavigationBar appearance] setBackgroundImage:myImage forBarMetrics:UIBarMetricsDefault];
在你的 - (void) applicationDidFinishLaunching:(UIApplication *)application
编辑: 似乎也有帮助:
[[UINavigationBar appearance] setTintColor:myColor];
关于objective-c - 为所有栏设置导航栏背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7914376/