Change tab bar item selected color in a storyboard
Add Runtime Color attribute named "tintColor" from StoryBoard. This is working(for Xcode 8 and above).
if you want unselected color.. you can add unselectedItemTintColor
too.
Changing tab bar item image and text color iOS
From UITabBarItem class docs:
By default, the actual unselected and selected images are
automatically created from the alpha values in the source images. To
prevent system coloring, provide images with
UIImageRenderingModeAlwaysOriginal.
The clue is not whether you use UIImageRenderingModeAlwaysOriginal, the important thing is when to use it.
To prevent the grey color for unselected items, you will just need to prevent the system colouring for the unselected image. Here is how to do this:
var firstViewController:UIViewController = UIViewController()
// The following statement is what you need
var customTabBarItem:UITabBarItem = UITabBarItem(title: nil, image: UIImage(named: "YOUR_IMAGE_NAME")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), selectedImage: UIImage(named: "YOUR_IMAGE_NAME"))
firstViewController.tabBarItem = customTabBarItem
As you can see, I asked iOS to apply the original color (white, yellow, red, whatever) of the image ONLY for the UNSELECTED state, and leave the image as it is for the SELECTED state.
Also, you may need to add a tint color for the tab bar in order to apply a different color for the SELECTED state (instead of the default iOS blue color). As per your screenshot above, you are applying white color for the selected state:
self.tabBar.tintColor = UIColor.whiteColor()
EDIT:
Change the color of selected tab bar icon in swift
Already answered here but in short, click on the tab bar item you wish to change and you can add a new runtime attribute in the Storyboard which will change the entire item (image & text) when selected.
how to change tabBar icon color in ios
This accomplishes what you're asking for:
[[UITabBar appearance] setSelectedImageTintColor:[UIColor redColor]];
[[UITabBar appearance] setAlpha:0.25];
How can I change the text and icon colors for tabBarItems in iOS 7?
There are two things you need to do for this:
1) If you want to customize the TabBar itself, you need to set the barTintColor for the tabBarController:
// this will generate a black tab bar
tabBarController.tabBar.barTintColor = [UIColor blackColor];
// this will give selected icons and text your apps tint color
tabBarController.tabBar.tintColor = appTintColor; // appTintColor is a UIColor *
2) Set the tabBarItem text appearance for each state that you want to override:
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],
NSForegroundColorAttributeName : appTintColor
} forState:UIControlStateSelected];
// doing this results in an easier to read unselected state then the default iOS 7 one
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],
NSForegroundColorAttributeName : [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:1]
} forState:UIControlStateNormal];
How do you change the color of unselected items in a Tab Bar?
Make the icon images Black, if they are white Im not sure it will work. As in the actual image themselves should be black in the assets folder not white.
If you add a tabbar from the story board you can put these line of code in that method in the appDelegate method shown in your post
UITabBar.appearance().barTintColor = UIColor.black
UITabBar.appearance().tintColor = UIColor.red
UITabBar.appearance().unselectedItemTintColor = .white
Related Topics
How to Check Bitfields (Scnetworkreachabilityflags in Particular) for Flags in Swift
iOS 14 Pickerview Cutting Off Text
Can't Build an App for Distribution After Joining Existing Enterprise Developer Program
Xcode Reference a Framework Instead of Link Binary with Libraries
Error Domain=Kclerrordomain Code=2 "The Operation Couldn't Be Completed. (Kclerrordomain Error 2.)"
Disabling Allowsbackgroundlocationupdates (Cllocationmanager) Doesn't Work After Is Was Enabled
How to Animate Dark Mode Change in iOS
Xcode Export App, Wildcard Error
How to Set Requestserializer in Alamofire
Restkit Request Not Sending Parameters
Issue Comparing Uicolors in Swift
Custom Uibarbuttonitem with Bg Colour and Text Swift 3
How to Launch IPA File in iOS 10 Real Device Using Appium 1.6.0
How to Override Convenience Init in Uialertcontroller for Swift
Swift: Is Correct to Use Stored Properties as Computed Properties