I've got a tabBar setup with 5 tabBarItems all going to different view controllers. I've set the project up so that when a tabBarItems is not selected, it is a grey tint color on both the text and image (I'm using system default images). What I am looking for is how to set each of the selected tabBarItems to different colors. EG, "Home" would have a red tint to both the text and image; "Social" would have a blue tint to both the text and image; "About" would have a green tint to both the text and image; etc etc
Asked
Active
Viewed 198 times
2 Answers
0
Already answered (Change tab bar item selected color in a storyboard) but in short, click on the tab bar item you wish to change and you can add a new runtime attribute in the Storyboard which will change the entire item (image & text) when selected.May Be its Helpful For you.

Gurpreet Singh
- 41
- 3
-
Hi, i've tried following this, have added a tintColor to each of the tabBarItems but they all still have the same single color (which I can change, just not indiviudally) – JPountney Apr 23 '20 at 14:45
0
If you define bar items, you can do it like this:
let array = [UIColor.red, UIColor.blue, UIColor.green]
implement UITabBarDelegate
@IBOutlet weak var tab3: UITabBarItem!
@IBOutlet weak var tab2: UITabBarItem!
@IBOutlet weak var tab1: UITabBarItem!
func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
if item == tab1 {
tabBar.tintColor = array[0]
}else if item == tab2 {
tabBar.tintColor = array[1]
}else {
tabBar.tintColor = array[2]
}
}
If you use TabBarController add this code to each viewControllers:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.tabBarController?.tabBar.tintColor = .green // change the color for each viewControllers
}

Kasım Özdemir
- 5,414
- 3
- 18
- 35
-
Hi, thanks for this, i'm new to swift - where would I add this code? To every one of the ViewControllers? – JPountney Apr 23 '20 at 15:05
-
Hi, I think you are using tabBarController so I edited my answer. – Kasım Özdemir Apr 23 '20 at 15:15
-