如何在 swift 3 中更改 TabBar 中禁用项目的颜色?

Sae*_*ahi 6 uitabbarcontroller uicolor uitabbaritem ios swift3

我的项目中有一个 TabBar,当用户选择项目时,该项目将禁用,但颜色也会改变!我希望颜色与我使用的 TabBar 中其他项目的颜色相同

item.isEnabled = false
Run Code Online (Sandbox Code Playgroud)

用于禁用项目,但此处的代码不适用于该项目

 override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    self.tabBar.barTintColor = UIColor.init(red: 126/255, green: 0/255, blue: 64/255, alpha: 1.0)
    if #available(iOS 10.0, *) {
        self.tabBar.unselectedItemTintColor = UIColor.white
        self.tabBar.unselectedItemTintColor = UIColor.white

    } else {
        // Fallback on earlier versions
    }
    UITabBar.appearance().tintColor = UIColor.white

}
Run Code Online (Sandbox Code Playgroud)

Abh*_*ain 2

试试这个代码 -

UITabBar.appearance().tintColor = UIColor.gray
UITabBar.appearance().unselectedItemTintColor = UIColor.gray
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!