UITabBar items with each one different color when selected

878 Views Asked by At

I have a multiple page tab bar application. I want each tab bar item (image) to have its own color when selected. For example, the first one should be red when selected, the second should be blue, the third should be yellow... I have tried to use this in my app delegate but it changes the color of all the selected images to the same color:

            UITabBar.appearance().tintColor = UIColor(red: 6/255, green: 162/255, blue: 198/255, alpha: 1)

I want each one to be different than the other when selected. I'm using swift 3.0. Any help please? Thanks.

1

There are 1 best solutions below

0
On

Add this line for every tab:

 tabBar.items![0].setTitleTextAttributes([NSForegroundColorAttributeName:UIColor(red: 1/255.0, green: 185/255.0, blue: 224/255.0, alpha: 1.0)], for: UIControlState.selected)