objective-c - 为所有栏设置导航栏背景图片

标签 objective-c three20 uinavigationbar xcode4.2

自从我更新到 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/

相关文章:

ios - 使用(正确的)txt 文件填充详细 View

ios - 将 subview 添加到 TTPhotoViewController 的 TTPhotoview

ios - 默认样式表样式在应用程序后期应用

ios - uisearchbar 导航栏颜色&状态颜色

ios - 将褪色的深色背景设置为 UINavigationBar

ios - UI_APPEARANCE_SELECTOR 不工作

ios - 是否可以将 UIView 移出 Controller 而不被剪切?

objective-c - NSXMLParser 不解析内部实体

iphone - Three20依赖问题

java - Android在底部导航栏中禁用缩放效果