user5168832
user5168832

Reputation: 69

Change the text and icon colors for UITabBar and UITabBarItems in XCODE 7 using swift 2.0?

How can I change the text and icon colors for UITabBar and UITabBarItems in XCODE 7 using SWIFT 2? The default gray text seems dim and hard to read for unselected tabbar items.

i want the text and icons white when inactive and this colour: #600c77 (purple) when active.

Upvotes: 0

Views: 581

Answers (1)

Mitesh Mistri
Mitesh Mistri

Reputation: 459

For your icon:

yourTabBar.tabBarItem = UITabBarItem(title: "Home", image: UIImage(named: "tab_icon_normal"), selectedImage: UIImage(named: "tab_icon_seelcted"))

For your text:

UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.YOURCOLOR()], forState:.Normal)

UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.YOURCOLOR()], forState:.Selected)

Upvotes: 2

Related Questions