Change color of tab bar items not selected


I wonder if someone knows how to change the color of the items in the tab bar in ios 9, now with the following code only the selected one is marked.

UITabBar.appearance().tintColor = UIColor.whiteColor()


I found a way to solve this and I publish it in case someone is interested. Change the color of the original images to the color that I would like them to have without being selected. Then I did the following:

  • Change the render of the image to: Original Image from Assets.
  • I added this code to color the text in both selected and unselected.

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

  • In each View controller, indicate the image of your tab item in both selected and unselected, also indicating the rendering of the image (there lies the trick so that the icon dyes the selected color)

    self.tabBarItem.selectedImage =  UIImage(named: "home")?.imageWithRenderingMode(.AlwaysTemplate)
    self.tabBarItem.image = UIImage(named: "home")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
  • And of course I added the line of code in the Appdelegate with which I started the question.

    UITabBar.appearance (). tintColor = UIColor.whiteColor ()

  • asked by Alejandro 11.08.2016 в 10:22

    1 answer


    You almost have it with your code. Simply use barTintColor instead of tintColor :

    UITabBar.appearance().barTintColor = UIColor.whiteColor()

    The tintColor modifies only the color of the UITabBar selected and instead the barTintColor modifies all the UITabBar .

    answered by 11.08.2016 в 11:30