0

I have tabBar with 5 items. My app start on first item and all has white color. When I tap on another item nothing change - this is clear, but is possible that when I tap on second item all the items change color to black or when I tap on third item their color change back to white?

1 Answers1

0

Yes, to achieve it you have to options depending on your setup, in both cases you have to implement the following method func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem):

  • If you are using a ViewController, it will have to implement the UITabBarController and UITabBarControllerDelegate. You will have to set the delegate property to self, you have to do it in the viewDidLoad method:

    self.delegate = self

  • If you are using a Tab Bar Controller Scene in your Storybard), create an instance of a UITabBarController class, in my example TabViewController, and set it as a custom class in your Tab View Controller.

enter image description here

Next, in both cases you will have to implement the following method:

override func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) 
    self.tabBar.tintColor = UIColor.red
}
Miquel Rigo
  • 61
  • 1
  • 3