此代碼可以在應用程序中的任何地方更改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