Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITabBar not changing tint color Xcode 9.3

This is very odd. My global tint is set and my icons colors are set to the default purple I have. Yet at run time its blue. Any tips? Ive checked around and have not seen anyone else with this problem.

Storyboard:

StoryBoard

Run Time:

Run Time

like image 674
Zack117 Avatar asked Dec 17 '22 22:12

Zack117


1 Answers

Basically, when you want to change the tint color of UITabBar programmatically, UITabBar class gives you several tint color properties:

  • tintColor: TabBarItem's color.
  • barTintColor : TabBar's background bar's color.
  • unselectedItemTintColor : color of unselected items.

so if you change the tintColor, barItems' color would be changed.


...but, Why it doesn't works on IB?

When you set a specific color to UITabBar's item in IB, there's an option named Image Tint.

imageTint

Changing a Tint option on "View" section won't affect anything to TabBar's items but only Image Tint option can change tabBar's item color.

storyboard's global tint color option changes Tint option of "View" section, but doesn't affect default value of Image Tint option, so It doesn't affect the tab bar's tint color.


So.. Why Image Tint option doesn't affected?

I can't explain why doesn't it affected. Maybe Apple had an issue with this, or kind of bug.


there are some workarounds for setting an image color :

  • Explicitly Set an Image Tint option to UITabBarController's TabBar object.

You may should set every TabBarController's Image Tint option, because it doesn't affects global setting.

  • Programmatically change global UITabBar's tintColor.

At AppDelegate.swift's didFinishLaunchingWithOptions, paste following code

UITabBar.appearance().tintColor = <#Color what you want#>
like image 141
Cyan Lee Avatar answered Dec 24 '22 00:12

Cyan Lee