[英]Is there a way to set the background color or navigation bar universally across an app?
現在,我必須在每次推送視圖之前執行類似下面的操作
_homeNavigationController.navigationBar.barStyle = UIBarStyleBlack;
_homeNavigationController.navigationBar.tintColor = nil;
我想用圖案圖像將顏色設置為不同的顏色。
那么有一個簡單的方法嗎?
如果您使用的是iOS 5,則可以使用外觀協議。
[[UINavigationBar appearance] setBackgroundImage:myImage];
文檔可以在這里找到:
如果要使用自定義色調顏色(內置常量除外),請使用以下代碼:
在全球范圍內定義這些。
#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define COLOR_NAVBAR_TINT RGBCOLOR(82, 154, 217)
#define COLOR_TOOLBAR_TINT RGBCOLOR(82, 154, 217)
將其添加到AppDelegate.m,然后在應用程序初始化期間調用它:
- (void)initializeGlobalTheme {
[[UINavigationBar appearance] setTintColor:COLOR_NAVBAR_TINT];
[[UIToolbar appearance] setTintColor:COLOR_TOOLBAR_TINT];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.