(Swift) selected tabBar Color?

I already know how to set the tabBar "barTintColor". I want to know how to set a specific color for the selected tabBar (as in the pic, the selected tabBar has a dark pink color). Just. Thanks in advance:)

Tab Bar

+3


source to share


1 answer


Change tintColor (whatever you are allowed to do)

Subclass UITabBarController, set it as the class of your UITabBarViewController:

class myOwnTBC: UITabBarController {
  override func viewDidLoad() {
    super.viewDidLoad()
    self.tabBar.tintColor = .blueColor()
  }
}

      

After further research following your comment:

I really believe Apple doesn't want the developer to change the background color of the UITabBar. Refer to the TabBar Interface Guide . I quote:



Tab bar: Semi-transparent

I tried subclassing the UITabBarItem and manipulating the background which gave me the following exception:

Directly change the tab bar driven by the tab bar. The controller is not allowed.

Decision?! You won't like this, but if you want to use the UITabBarController you should stick with the semi-transparent preset.

Workaround? The only workaround I can think of in Moment is: Create your own navigation using your own UIView-Subclass. This would violate interface principles anyway, but you can achieve your goal.

+2


source







All Articles