如何在 swift 3 中更改 TabBar 中禁用的项目颜色? [英] how to change disabled item color in TabBar in swift 3?

查看:47
本文介绍了如何在 swift 3 中更改 TabBar 中禁用的项目颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a TabBar in my project and when user select item this item will disable but the color will change too! I want the color is same as other items color in TabBar I used

item.isEnabled = false

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

for disable item but this codes here won't work for this item

 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

}

推荐答案

试试这个代码 -

UITabBar.appearance().tintColor = UIColor.gray
UITabBar.appearance().unselectedItemTintColor = UIColor.gray

希望这会有所帮助!

这篇关于如何在 swift 3 中更改 TabBar 中禁用的项目颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆