我想将导航栏的背景设置为黑色,并将其中的所有颜色设置为白色。
所以,我使用了这段代码:
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],
NSForegroundColorAttributeName,
[UIColor whiteColor],
NSForegroundColorAttributeName,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
NSForegroundColorAttributeName,
[UIFont fontWithName:@"Arial-Bold" size:0.0],
NSFontAttributeName,
nil]];
但后退按钮文字颜色、箭头和条形按钮仍然有默认的蓝色。
如何更改下图中的颜色?
最佳答案
UINavigationBar
的某些属性的行为已从 iOS 7 更改。您可以在下图中看到:
我想与您分享两个漂亮的链接。有关更多详细信息,您可以通过这些链接:
Apple 文档 for barTintColor说:
This color is made translucent by default unless you set the translucent property to 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;
https://stackoverflow.com/questions/19029833/