I have an UITabBar with 5 items. I want to change the unselected color of all items. The items aren't declared in the UIViewController classes (i built them and linked the views in the Storyboard).
Is there an code like this : [[UITabBar appearance] set***UN***SelectedImageTintColor:[UIColor whiteColor]];
?
Translating user3719695's answer to Swift, which now uses extensions:
UIImage+Overlay.swift
customTabBar.swift
@JoeGalid's
imageWithColor:
solution with Xamarin:Then utilize it when setting up the tab bar items:
In iOS 10 and higher, there are 3 possible easy solutions:
A. Instance from code (Swift):
B. Instance from IB:
Add a Key Path:
unselectedItemTintColor
of type:Color
C. Global appearance (Swift):
I had to move the code into
viewWillAppear
because inviewDidLoad
the images weren't set yet.Swift 4 Translation
Referring to the answer from here: UITabBar tint in iOS 7
You can set the tint color for selected and unselected tab bar buttons like this:
The first line sets the unselected color - red in this example - by setting the UIView's tintColor when it's contained in a tab bar. Note that this only sets the unselected image's tint color - it doesn't change the color of the text below it.
The second line sets the tab bar's selected image tint color to green.
The new answer to do this programmatically as of iOS 10+ is to use the
unselectedItemTintColor
API. For example, if you have initialized your tab bar controller inside yourAppDelegate
, it would looks like the following: