我需要将UINavigationBars背景颜色设置为与我的应用程序全局色调颜色相同的值。
问题在于,现在导航栏中的所有按钮都与其背景颜色相同。我现在可以将所有UIBarButtons文本颜色更改为白色,但这将完全无法使用。使用UIAppearance API似乎不是更好的方法。将UIBarButton项目的文本颜色设置为白色后,f。我的UINavigationBar中后退按钮的后退箭头仍然使用全局色调颜色绘制。
如果我将全局色调颜色更改为白色,我会失去全局色调给我们的所有灵活性(我的文本指示器现在也是白色的,不会在白色背景上看到)
我想要的是什么:
我使用蓝色作为全局色调
当使用蓝色作为全局色调并将uibarbutton项目文本颜色设置为白色时我得到的结果(请参阅后退按钮 - 它也应该是白色的)
解决此问题的推荐方法是什么?
答案 0 :(得分:5)
我建议您这样做:
UINavigationBar *navigationBar = [UINavigationBar appearance];
navigationBar.tintColor = [UIColor whiteColor];
将此代码放在AppDelegate中的didFinishLaunchingWithOptions:方法中。
澄清一下,因为你显然对此不太熟悉:
barTintColor
是可以更改条形颜色的属性。 tintColor
更改交互式对象的颜色(例如UIBarButtonItem
s)
答案 1 :(得分:4)
if ([[UINavigationBar class] respondsToSelector:@selector(appearance)]) {
[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
}
答案 2 :(得分:0)
尝试在指定的控制器中设置UINavigationBar setTintColor(例如在viewDidLoad中)。