Witterquick
Witterquick

Reputation: 6140

UITabBar icons text color

How can I change the text color of UITabBar (which is contained in UINavigationController if it's matters) ? If I write this -

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

then the color would be green as expected, but if I write this -

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

The text becomes invisible

The same goes for

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

Upvotes: 0

Views: 66

Answers (2)

Ivan C Myrvold
Ivan C Myrvold

Reputation: 840

You must divide the red, green and blue by 255, like this

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

Upvotes: 3

Dejan Atanasov
Dejan Atanasov

Reputation: 1232

Please try writing it like this:

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

Upvotes: 3

Related Questions