将自定义颜色设置为UITabBarItem不起作用

时间:2016-06-15 21:42:08

标签: ios swift cocoa-touch

我正在尝试更改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)

它不起作用。

还有其他选项可以将所选文字颜色更改为我想要的任何颜色吗?

感谢名单

1 个答案:

答案 0 :(得分:0)

您正在使用的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