UITabBar图标文字颜色

时间:2016-05-29 10:14:57

标签: ios swift

如何更改UITabBar的文本颜色(如果它很重要,它包含在UINavigationController中)? 如果我写这个 -

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

然后颜色会像预期的那样变成绿色,但如果我写这个 -

UITabBar.appearance().tintColor = UIColor(red: 255, green: 255, blue: 255, alpha: 1.0)

文字变得不可见

同样如此
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.redColor()], forState:.Selected) //red color 

UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor(red: CGFloat(104), green: CGFloat(154), blue: CGFloat(26), alpha: CGFloat(1))], forState:.Selected) //invisible

2 个答案:

答案 0 :(得分:3)

请尝试这样写:

UITabBar.appearance().tintColor = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)

答案 1 :(得分:3)

你必须将红色,绿色和蓝色除以255,就像这样

UIColor(red:255/255.0, green:255/255.0, blue: 255/255.0, alpha: 1.0)