简体   繁体   English

使用全局色调颜色作为UINavigationBars backgroundColor

[英]Using global Tint color as UINavigationBars backgroundColor

i need to set the UINavigationBars background color to the same value as my apps global tint color. 我需要将UINavigationBars背景颜色设置为与我的apps全局色调颜色相同的值。

problem here is that now all buttons in my navigation bar are the same color as its background. 这里的问题是,导航栏中的所有按钮都与其背景颜色相同。 i now could change all UIBarButtons text color to white but this would be totally unusable. 我现在可以将所有UIBarButtons文本颜色更改为白色,但这将完全无法使用。 using the UIAppearance API doesn't seem to be a better way. 使用UIAppearance API似乎不是更好的方法。 after setting the text color of UIBarButton items to white, fe the back arrows of the back button in my UINavigationBar are still painted with the global tint color. 将UIBarButton项目的文本颜色设置为白色后,我的UINavigationBar中后退按钮的后退箭头仍然使用全局色调颜色绘制。

also if i change the global tint color to white i loose all the flexibility that the global tint color gives us (also my text indicator would now be white and would not be seen on a white background) 另外,如果我将全局色调颜色更改为白色,我会失去全局色调给我们的所有灵活性(我的文本指示器现在也是白色的,不会在白色背景上看到)

what i want: 我想要的是:

在此输入图像描述

what i get using blue as global tint color 我用蓝色作为全球色彩的颜色

在此输入图像描述

what i get when using blue as global tint color and setting uibarbutton items text color to white (see the back button - it should be white as well) 当使用蓝色作为全局色调并将uibarbutton项目文本颜色设置为白色时我得到的结果(请参阅后退按钮 - 它也应该是白色的)

在此输入图像描述

what is the recommended way to fix this problem? 修复此问题的推荐方法是什么?

I recommend that you do this: 我建议你这样做:

UINavigationBar *navigationBar      = [UINavigationBar appearance];
navigationBar.tintColor             = [UIColor whiteColor];

Place this code in the didFinishLaunchingWithOptions: method in the AppDelegate. 将此代码放在AppDelegate中的didFinishLaunchingWithOptions:方法中。

For clarification as you are obviously not very experienced with this: 为了澄清,因为您显然对此不太熟悉:

barTintColor is the property that would change the bar colour. barTintColor是可以更改条形颜色的属性。 tintColor changes the colour of interactive objects (such as the UIBarButtonItem s) tintColor更改交互式对象的颜色(例如UIBarButtonItem

if ([[UINavigationBar class] respondsToSelector:@selector(appearance)]) {
    [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
}

尝试在指定的控制器中设置UINavigationBar setTintColor(例如在viewDidLoad中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM