我正在尝试更改 TabBarItem 的选定文本颜色。
如果我使用:
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.blackColor()], forState: .Selected)
它有效...
但是如果我使用:
let darkColor = UIColor(red: 44, green: 62, blue: 80, alpha: 1)
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName : darkColor], forState: .Selected)
它不起作用。
是否有其他选项可以将所选文本颜色更改为我想要的任何颜色?
谢谢
最佳答案
您使用的 UIColor
初始值设定项接受 0.0 到 1.0 范围内的值 - 您只需将它们映射到您使用的 0 - 255 范围内即可。
这应该有效:
UIColor(red: 44.0/255.0, green: 62.0/255.0, blue: 80.0/255.0, alpha: 1.0)
相关docs
关于ios - 将自定义颜色设置为 UITabBarItem 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37846272/