The color of the UITabBarItem image is gray and the original image is white

I am using the following code to create an image for my UITabBarItem

 self.tabBarItem.image = [UIImage imageNamed:@"tab_img.png"]; 

This tab_img.png consists of black, white and clear color. But in the application, the entire part of the image in black and white becomes gray. How can I change this gray to white?

this is image that I use

enter image description here

+10
ios objective-c iphone ipad
Feb 26 '13 at 10:07
source share
6 answers

In iOS7, if you use IB, you can subclass UITabBarController, and then add this:

 + (void)initialize { //the color for the text for unselected tabs [UITabBarItem.appearance setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor redColor]} forState:UIControlStateNormal]; //the color for selected icon [[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]]; } - (void)viewDidLoad { [super viewDidLoad]; if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) { for (UITabBarItem *tbi in self.tabBar.items) { tbi.image = [tbi.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; } } } 

if you create the items manually, you must set UIImageRenderingModeAlwaysOriginal to each icon and add the code from the initialization.

+32
Apr 08 '14 at
source share

Set the selected and unselected image.

 [self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"mehr_icon"] withFinishedUnselectedImage:[UIImage imageNamed:@"mehr_icon"]]; 
+10
Feb 26 '13 at 10:54
source share

images for UITabBarItems should only be an alpha channel! the opaque part will only appear gray (blue if selected)!

take a look at: http://devinsheaven.com/creating-uitabbar-uitoolbar-icons-in-adobe-illustrator/

+3
Feb 26 '13 at 10:14
source share

If you use image objects, just set the “Render As” field to your images (selected and unselected images) in “Original Image” ( example )

Then, in your xib, set the Image and Selected Image fields in the tab bar. ( example )

+1
Sep 01 '17 at 9:30
source share

I had the same problem once, I use images with white and alpha only as an image

I installed it using self.tabBarItem.image = [UIImage imageNamed:@"Liste"];

0
Feb 26 '13 at 10:19
source share

The only way is to go to IB (interface builder) and select UITabBarItem in your view controller and go to the “file inspector”, scroll down and you will see “Global Tint”, you can set it without the color or any color you want, so that it takes effect for the selected image.

according to the following code is troubling

 setFinishedSelectedImage: withFinishedUnselectedImage:; 

it is no longer available in iOS 7, we can use

 [yourCustomTabBarItem setSelectedImage:---]; 

but it will also take effect on this global color shades.

0
Nov 22 '13 at 7:33
source share



All Articles