首页 文章

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

提问于
浏览
3

我需要将UINavigationBars背景颜色设置为与我的apps全局色调颜色相同的值 .

这里的问题是,导航栏中的所有按钮都与其背景颜色相同 . 我现在可以将所有UIBarButtons文本颜色更改为白色,但这将完全无法使用 . 使用UIAppearance API似乎不是更好的方法 . 将UIBarButton项目的文本颜色设置为白色后,f . 我的UINavigationBar中后退按钮的后退箭头仍然使用全局色调颜色绘制 .

另外,如果我将全局色调颜色更改为白色,我会失去全局色调给我们的所有灵活性(我的文本指示器现在也是白色的,不会在白色背景上看到)

我想要的是:

enter image description here

我用蓝色作为全球色彩的颜色

enter image description here

当使用蓝色作为全局色调并将uibarbutton项目文本颜色设置为白色时我得到的结果(请参阅后退按钮 - 它也应该是白色的)

enter image description here

修复此问题的推荐方法是什么?

3 回答

  • 5

    我建议你这样做:

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

    将此代码放在AppDelegate中的didFinishLaunchingWithOptions:方法中 .

    为了澄清,因为您显然对此不太熟悉:

    barTintColor 是可以更改条形颜色的属性 . tintColor 更改交互式对象的颜色(例如 UIBarButtonItem

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

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

相关问题