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]];
?
Swift 4 version (Without implicitly unwrapping Optionals) :
UIImage+Overlay.swift
CustomTabBarController.swift
Or just without coding. Swift 4, Xcode 10.1.
UITabBar
on your View Controller using Interface Builder.cmd + alt + 3
or just clickShow the Identity Inspector
in the right panel.User Defined Runtime Attributes
click on plus button to add a new attribute and call it asunselectedItemTintColor
(see here).Type
column chooseColor
type.Value
section.Extending @Sven Tiffe’s answer for iOS 7, you can get your code to automatically tint the unselected UITabBar images added in the storyboard. The following approach will save you having to create two sets of icon images (i.e. selected vs unselected) and having to programatically load them in. Add the category method imageWithColor: (see - How can I change image tintColor in iOS and WatchKit) to your project then put the following in your custom UITabBarController viewDidLoad method:
Create a Category called UIImage+Overlay and on UIImage+Overlay.m (extracted from this answer ) :
Swift version in iOS 10 and higher -
SO says i cannot delete the accepted answer (i tried), but obviously, there are a lot of upvotes for comments that this doesn't work for iOS 7.
See the other answer below with many more upvotes, or the link in @Liam's comment to this answer.
for iOS 6 only
It should be as simple as this:
This will not work under iOS 7 as far as I can say. In particular, tintColor of the tab bar will define the color of the selected tab, not of the unselected ones. If you want to change the default in iOS 7, it seems that you have to actually use different icons (in the color you like to have for unselected tabs) and set the color of the text.
This example should tint selected tabs to red and render others in green. Run this code in your TabBarController:
If you set the icon in the story board only, you can control the color of the selected tab only (tintColor). All other icons and corresponding text will be drawn in gray.
Maybe someone knows an easier way to adopt the colors under iOS 7?