这段代码可以改变应用程序中任何地方的UINavigationBar
的颜色。但是,我注意到它不会改变由UINavigationController
使用的UINavigationBar
的UIColor
(我的UINavigationBar
来自一个UIStoryboard
)。
UIColor* navBarColor = [UIColor colorWithRed:arc4random()%100/100.0
green:arc4random()%100/100.0
blue:arc4random()%100/100.0
alpha:1];
[[UINavigationBar appearance] setTintColor:navBarColor];
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlackTranslucent];
[[UINavigationBar appearance] setAlpha:0.7];
有没有一种方式可以访问UINavigationController
导航栏的appearance
对象? 我知道如何设置单个控制器的色调,但我想全局控制它们的外观。
更新:
这是我的错误,该代码确实会更改所有UINavigationBar
的UIColor
,但需要覆盖和取消覆盖根导航控制器(例如呈现模态视图控制器),然后它会用新的UIColors
重新绘制自己!
谢谢!
UITextAttributeTextColor
和UITextAttributeShadowColor
已被弃用 - 请改用NSForegroundColorAttributeName
和NSShadowAttributeName
。 - thomers