6

In iOS 7, I been developing an app that uses the UITabBarController and I noticed that the tab bar items stay gray even tho I change the tint color of the tab bar. Is there any way to change the color of non-selected tab bar items?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Reza Safari
  • 377
  • 2
  • 4
  • 6

3 Answers3

6

To do this:: follow a simple approach..

  1. Change tintColor as you want

  2. Add a new set of images for unselected items and render them in original mode.

For more info, read through this link

Community
  • 1
  • 1
Balram Tiwari
  • 5,657
  • 2
  • 23
  • 41
6

To sets the tint color globally for the app, you need to add below code In app delegate didFinishLaunchingWithOptions: method:

[[UITabBar appearance] setTintColor:[UIColor colorWithRed:13.0/255.0 green:116.0/255.0 blue:128.0/255.0 alpha:1.0]];
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Iya
  • 1,888
  • 19
  • 12
  • 1
    Please consider editing your answer to include an explanation of how your code works. – Matt Oct 21 '15 at 05:30
0

Changing the tabBar.tintColor property is the right way to do it, however to make it work we need to tell iOS to ignore color properties of the UIImage in TabBarItem. Hence write this code in your custom TabBarViewController's viewDidLoad()

for item in self.tabBar.items ?? [] {
    item.selectedImage = item.selectedImage?.withRenderingMode(.alwaysTemplate)
    item.image = item.image?.withRenderingMode(.alwaysTemplate)
}
MMujtabaRoohani
  • 483
  • 4
  • 19