Here is my tab bar:
The following image shows the program being run and the "NEWS" item selected:
It is clear the bar tint color is working fine as I want !
But the tintColor only affects the image and not the text.
Also, when the an item is selected (as seen above, news) the item color goes blue! How do I prevent this from happening? I want it to stay white.
Why is the text changing to a white color when selected but not when it is unselected?
I basically want the item color and text color to be white all the time.
How do I achieve this? Thanks for any help.
Does it require swift code for each individual item?
EDIT:
Try add it on AppDelegate.swift (inside application method):
Example:
Example:
My english is so bad! I'm sorry! :-)
Simply add a new UITabBarController reference to the project.Next create a reference of UITabBar in this controller:
In its viewDidLoad(), simply add below for title text color:
For image
Swift 4.2 and Xcode 10
The solution that worked for me:
This will prevent the Tab bar component from setting its default image tint.
Text - here I created a simple UITabBarController subclass and in its viewDidLoad method I customized the default and selected text color like this:
Just set this class as your Tab bar controller custom class in identity inspector in IB.
Voila! That's it.
iOS 13 Update:
Add this to your setup for iOS 13:
Swift 4: In your UITabBarController change it by this code
Swift 3
First of all, make sure you have added the BOOLEAN key "View controller-based status bar appearance" to Info.plist, and set the value to "NO".
Appdelegate.swift
Insert code somewhere after "launchOptions:[UIApplicationLaunchOptionsKey: Any]?) -> Bool {"
UITabBar.appearance().barTintColor = UIColor(red: 0.145, green: 0.592, blue: 0.804, alpha: 1.00)
OR one of the default UI colors:
UITabBar.appearance().barTintColor = UIColor.white)
The selected item
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.white], for: .selected)
The inactive items
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.black], for: .normal)
If you don´t make the icons from scratch, alternating black and white versions are relatively easy to make in Photoshop.
Adobe Photoshop (almost any version will do)
Make sure your icon image has transparent background, and the icon itself is solid black (or close).
Open the image file, save it under a different file name (e.g. exampleFilename-Inverted.png)
In the "Adjustments" submenu on the "Image" menu:
Click "Invert"
You now have a negative of your original icon.
In XCode, set one of the images as "Selected Image" under the Tab Bar Properties in your storyboard, and specify the "inactive" version under "Bar Item" image.
Ta-Da
Swift 3
This worked for me (referring to set tabBarItems image colors):
I have noticed that if you set image with rendering mode = .alwaysOriginal, the UITabBar.tintColor doesn't have any effect.