【问题标题】:Presented UINavigationController tint color not changing呈现的 UINavigationController 色调颜色不变
【发布时间】:2013-09-03 16:55:25
【问题描述】:
MyVC *vc = [[MyVC alloc] init];
vc.delegate = self;
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];
[nc.navigationBar setTintColor:[UIColor redColor]];
[self presentViewController:nc animated:true completion:^{}];
导航栏是黑色的。我从在我的 App Delegate 中创建的选项卡栏控制器内的导航控制器呈现此内容。在我的 ApplicationDidFinishLaunchingWithOptions 中,我可以在那里控制导航控制器的颜色。
为什么这个导航控制器的色调条是黑色的?
【问题讨论】:
标签:
ios
objective-c
uinavigationcontroller
uinavigationbar
【解决方案1】:
[[UINavigationBar appearance] setTintColor:[UIColor redColor]];
如果您所有的 NavigationBars 都是相同的颜色,我建议您使用它。对象的外观属性设置了您对其应用的功能的一致性。
【解决方案2】:
- 您可以尝试为 UINavigationBar 制作自定义类
.h
@interface CustomUINavigationBar : UINavigationBar {
}
@end
.m
@implementation CustomUINavigationBar
- (void)drawRect:(CGRect)rect {
UIColor *color = [UIColor colorWithRed:0.023 green:0.14 blue:0.478 alpha:1];// for example
self.tintColor = color;
}
@end
您也可以尝试在 AppDelegate.m 的 didFinishLaunchingWithOptions: 中插入以下代码
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
【解决方案3】:
在iOS7 中你必须使用barTintColor 属性
[nc.navigationBar setBarTintColor:[UIColor redColor]];
而不是
[nc.navigationBar setTintColor:[UIColor redColor]];