3 回答

TA貢獻1906條經驗 獲得超3個贊
UINavigationBar從iOS 7開始,某些屬性的行為已更改。您可以在下面顯示的圖像中看到:
我想與您分享兩個美麗的鏈接。有關更多詳細信息,您可以通過以下鏈接:
iOS 7 UI過渡指南。
如何為iOS更新您的應用程序7。
蘋果文檔的barTintColor說:
除非您將半透明屬性設置為NO,否則默認情況下此顏色為半透明。
樣例代碼:
self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
[self.navigationController.navigationBar
setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
self.navigationController.navigationBar.translucent = NO;

TA貢獻1848條經驗 獲得超6個贊
這花了我大約半天時間才弄清楚,但這對我有用。在用于初始化navigationController的rootViewController中,將以下代碼放入viewDidAppear方法中:
//set bar color
[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:85.0/255.0 green:143.0/255.0 blue:220.0/255.0 alpha:1.0]];
//optional, i don't want my bar to be translucent
[self.navigationController.navigationBar setTranslucent:NO];
//set title and title color
[self.navigationItem setTitle:@"Title"];
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor]];
//set back button color
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor,nil] forState:UIControlStateNormal];
//set back button arrow color
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];

TA貢獻1834條經驗 獲得超8個贊
Swift3,iOS 10
要全局分配顏色,請在AppDelegate中didFinishLaunchingWithOptions:
let textAttributes = [NSForegroundColorAttributeName:UIColor.white]
UINavigationBar.appearance().titleTextAttributes = textAttributes
Swift 4,iOS 11
let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white]
UINavigationBar.appearance().titleTextAttributes = textAttributes
- 3 回答
- 0 關注
- 1042 瀏覽
添加回答
舉報