【问题标题】:How to definitively set UITabBar background color and tint color如何明确设置 UITabBar 背景颜色和色调颜色
【发布时间】:2016-10-04 05:28:51
【问题描述】:

我已经尝试设置我的UITabBar 的色调颜色和背景颜色已经有一段时间了,但似乎没有任何效果。 到目前为止,我已经尝试过:

tabBarController?.tabBar.backgroundColor = UIColor.orangeColor()
tabBarController?.tabBar.barTintColor = UIColor.whiteColor()

还有:

UITabBar.appearance().tintColor = UIColor.orangeColor()

这些似乎都对我的标签栏没有任何影响。我还想提一下,我将 VC 嵌入在导航控制器中,我为其设置的全局色调颜色可以正常工作。

【问题讨论】:

    标签: ios swift uitabbar


    【解决方案1】:

    设置标签栏背景颜色用barTintColor

    self.tabBar.barTintColor = UIColor.blueColor()
    //or
    UITabBar.appearance().barTintColor = UIColor.blueColor()
    

    对于标签栏的色调颜色:

    self.tabBar.tintColor = UIColor.whiteColor() // Selected tab color
    //or
    UITabBar.appearance().tintColor = UIColor.whiteColor()
    

    【讨论】:

    • 我的 tabBar 看起来像这样但是当用户点击任何选项卡时,该项目将禁用但颜色也会改变我该如何更改?这是我的问题链接stackoverflow.com/a/45439032?noredirect=1
    • 颜色接近但不一样。尝试将视图背景设置为相同的颜色并亲自查看
    • +1 用于解释tintColorbarTintColor 之间的区别。有没有可能想出更多晦涩和无用的属性名称,Apple?
    【解决方案2】:

    如果你想隐式设置标签栏的tint and barTint color,那么在你的Appdelegate.swift中,

        UITabBar.appearance().barTintColor = .orange
        UITabBar.appearance().tintColor = .green
    

    如果你想为特定的viewController设置标签栏的tint and barTint color然后在ViewController.swift

     self.tabBarController?.tabBar.tintColor = .orange
     self.tabBarController?.tabBar.barTintColor = .green
    

    【讨论】:

    • 嗨@Lion,这个UITabBar.appearance().barTintColor中不存在barTintColor?
    • @Khuong 我可以通过访问实例来访问它,但我无法通过 appearance() 的类来访问它
    • @Khuong 在那里,只是 Xcode 完全拒绝在自动完成选项中显示它
    • swift 4: UITabBar.appearance().barTintColor = UIColor.orange UITabBar.appearance().tintColor = UIColor.green
    • UITabBar.appearance().backgroundColor = UIColor.green 似乎什么也没做。 barTint 接近但绝对不一样。这是预期的吗?
    【解决方案3】:

    Swift 4+ 版本

    UITabBar.appearance().barTintColor = UIColor.red
    UITabBar.appearance().tintColor = UIColor.white
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-11
    • 1970-01-01
    • 2011-05-16
    • 2011-04-14
    • 1970-01-01
    • 2010-12-11
    • 2021-10-26
    • 2020-12-14
    相关资源
    最近更新 更多