【发布时间】:2014-03-17 09:12:09
【问题描述】:
我将按钮单击时条形颜色设置为不同,但您必须切换视图才能使以下方法生效。我不知道为什么不是。
[[UINavigationBar appearance] setBarTintColor:[UIColor darkGrayColor]];
谢谢:D
【问题讨论】:
标签: ios uiappearance bartintcolor
我将按钮单击时条形颜色设置为不同,但您必须切换视图才能使以下方法生效。我不知道为什么不是。
[[UINavigationBar appearance] setBarTintColor:[UIColor darkGrayColor]];
谢谢:D
【问题讨论】:
标签: ios uiappearance bartintcolor
错误原因:
[[UINavigationBar appearance] setBarTintColor:[UIColor randomColor]];不起作用,因为 UIViewController 已经 初始化!!!
解决办法:
(1) UIAppearance 用户在 AppDelegate didFinishLaunch 函数中设置全局效果。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[[UINavigationBar appearance] setBarTintColor: [UIColor redColor]];
return YES;
}
(2) 关于初始化的 UIViewController ,你应该使用 self.navigationController.navigationBar 设置颜色,也会对应用的生命周期产生影响。
[self.navigationController.navigationBar setBarTintColor:[UIColor randomColor]];
【讨论】:
UINavigationBar *navBar=self.navigationController.navigationBar;
[navBar setBarTintColor:[UIColor darkGrayColor]];
试试这个
这就是我测试它的方式。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UINavigationBar *navBar=self.navigationController.navigationBar;
[navBar setBarTintColor:[UIColor darkGrayColor]];
}
因为我在屏幕上没有任何按钮,所以我只是更改了我的一个表委托函数。
【讨论】: