How to set Image in Tabbar not Tint color in ios?
You need to set your image attributes property Render As
to Original Image
. To change this select your image from assets and in the Attributes Inspector
set Render As
property to Original Image
like this.
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:
Swift: Change the image tint color of tab bar?
In your 'application:didFinishLaunchingWithOptions'
(window?.rootViewController as! UITabBarController).tabBar.tintColor = UIColor.red
or use appearance delegate.
UITabBar.appearance().tintColor = UIColor.red
UITabBar not changing tint color Xcode 9.3
Basically, when you want to change the tint color of UITabBar
programmatically, UITabBar
class gives you several tint color properties:
tintColor
:TabBarItem
's color.barTintColor
:TabBar
's background bar's color.unselectedItemTintColor
: color of unselected items.
so if you change the tintColor
, barItems' color would be changed.
...but, Why it doesn't works on IB?
When you set a specific color to UITabBar's item in IB, there's an option named Image Tint
.
Changing a Tint
option on "View" section won't affect anything to TabBar's items but only Image Tint
option can change tabBar's item color.
storyboard's global tint color option changes Tint
option of "View" section, but doesn't affect default value of Image Tint
option, so It doesn't affect the tab bar's tint color.
So.. Why Image Tint
option doesn't affected?
I can't explain why doesn't it affected. Maybe Apple had an issue with this, or kind of bug.
there are some workarounds for setting an image color :
- Explicitly Set an
Image Tint
option to UITabBarController's TabBar object.
You may should set every TabBarController
's Image Tint
option, because it doesn't affects global setting.
- Programmatically change global UITabBar's tintColor.
At AppDelegate.swift
's didFinishLaunchingWithOptions
, paste following code
UITabBar.appearance().tintColor = <#Color what you want#>
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
Dateformatter Returns Unexpected Date for Timezone
Z-Index Issue on iOS Safari & Chrome
Fixing Xcode 9 Issue: "iPhone Is Busy: Preparing Debugger Support for Iphone"
How to Draw Border Around a Uilabel
Build Not Visible in Itunes Connect
Storyboards VS. the Old Xib Way
How to Combine Two Dictionary Instances in Swift
How Can an iOS 7 App Make Itself Transparent to See a User's Home Screen Image
Repeating Local Notification Daily at a Set Time with Swift
Convert String to Nsurl Is Return Nil in Swift
Why Can't I Force Landscape Orientation When Use Uinavigationcontroller
Xcode 10: a Valid Provisioning Profile for This Executable Was Not Found
Xcode Suddenly Stopped Running Project on Hardware: "Could Not Launch Xxx.App: .. No Such File.."
iOS Designated Initializers:Using Ns_Designated_Initializer