我想设置Navigation Bar的背景颜色为黑色,然后所有内部颜色为白色.
因此,我用了这段代码:
[[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]
];
但是,返回按钮文本颜色,箭头颜色以及导航栏按钮的颜色仍然为默认颜色,怎么修改它们?
解决方法 1:
自从IOS7后UINavigationBar的一些属性的行为发生了变化.你可以在下图看到:
enter image description here
现在,如果你要修改它们的颜色,用下面的代码:
self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
self.navigationController.navigationBar.translucent = NO;