1

I'm trying to change the color of the icons in my TabBarController. I've successfully changed the textcolor (just below the icons), but cant figure out how I change the icon color.

I've changed the icon-text-color like this:

UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState:.Selected)
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.whiteColor()], forState:.Normal)

I've put this into my AppDelegate.swift (didFinishLaunchingWithOptions). Now the selected item-text is orange, and the unselected are white. The icons however are still in blue / dark gray. How do I change these?

Unselected:

Unselected

Selected:

Selected

vaultah
  • 44,105
  • 12
  • 114
  • 143
0x52
  • 883
  • 1
  • 11
  • 17
  • Possible duplicate of [Change tab bar item selected color in a storyboard](http://stackoverflow.com/questions/26835148/change-tab-bar-item-selected-color-in-a-storyboard) – Marcelo Gracietti Jan 01 '17 at 23:20

2 Answers2

2

being tBVC my tabBarViewController, I just do:

tBVC.tabBarItem.selectedImage = UIImage(named: "k-lenda(Hi)")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
tBVC.tabBarItem.image = UIImage(named: "k-lenda(Lo)")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)

And in the attributes inspector I have the "Hi" image for the Bar Item.

I hope it helps !

Code Lღver
  • 15,573
  • 16
  • 56
  • 75
Marcos
  • 461
  • 6
  • 10
1

Set tintColor property by UIAppearance.

Yoichi Tagaya
  • 4,547
  • 2
  • 27
  • 38
  • 1
    Thank you, I was now able to change the color of the selected item. But how do I change the color of the unselected items-icons? – 0x52 Mar 05 '15 at 12:59
  • 1
    I think you need to use `init(title:image:selectedImage:)` to create UITabBarItem instances, and the images should be configured as `UIImageRenderingModeAlwaysOriginal`. Check the UITabBarItem reference. – Yoichi Tagaya Mar 05 '15 at 13:44