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:
you can set tintColor of UIBarItem :
For Swift 4.0, it's now changed as:
You don't have to subclass the UITabBarItem if your requirement is only to change the text color. Just put the above code inside your view controller's
viewDidLoad
function.For global settings change
tabBarItem
toUITabBarItem.appearance()
.Swift 3.0
I created the tabbar class file and wrote the following code
In
viewDidLoad
:After
viewDidLoad
:in view did load method you have to set the selected image and other image are showing with RenderingMode and in tab bar delegate methods you set the selected image as per title
This Code works for Swift 4 if you want to change the image of
Tab Bar Item
when pressed. Copy and paste in the firstviewDidLoad
method that is hit in the projectSwift 3
I did it by creating a custom tabbar controller and added this code inside the
viewDidLoad
method.It worked for me!
I know here are lots of answers but I can't find an easy and valid copy/paste answer for Swift 4.2/ Swift 5.1
Or use
UITabBarItem.appearance()
instead oftabBarController?.tabBar
Images have to be UIImageRenderingModeAlwaysTemplate