此代码可以在应用程序中的任何地方更改UINavigationBar
的颜色。然而,我注意到它并没有改变的UINavigationBar
所使用的UINavigationController
(我的来自UIStoryboard
)。UINavigationController以全局方式和编程方式更改导航栏的色调颜色
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's
导航栏的appearance
对象的方法吗?我知道如何设置单个控制器的色调,但我想要全局控制它们的外观。
更新: 这是我的错误,代码不会改变所有UINavigationBars
的UIColor
,但它需要的根导航控制器被覆盖和未覆盖(例如呈现模态视图控制器),然后将重新抽签本身与新的UIColors
!
谢谢!
注意'UITextAttributeTextColor'和'UITextAttributeShadowColor'已弃用 - 使用'NSForegroundColorAttributeName'和'NSShadowAttributeName'代替。 – thomers 2017-06-21 09:28:18