Question

After iOS 7.1 update, I can't see the images of the tabBar but if I click on one image it appears. I've the following code to set the images of tabBar items

UINavigationController* myController;

 .. //some code here

 myController.tabBarItem.image = [UIImage imageNamed:@"someImage.png"];
 myController.navigationBar.barTintColor = myColor;
 myController.navigationBar.translucent = NO;

//and so on for the remaining controllers, then I add them to the tabBarController

I searched for the problem and I found that I should add selectedImage but it did not work

myController.tabBarItem.selectedImage = [UIImage imageNamed:@"someImage.png"];

Any idea?

I fixed the problem check my answer

Was it helpful?

Solution

I updated my code to the following and it works now. I fixed the problem by using imageWithRenderingMode.

//This is the line that I updated 
myController.tabBarItem.image = [[UIImage imageNamed:@"someImage.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];

//And added this line too, I used the same original image not new one for the selected case 
myController.tabBarItem.selectedImage = [UIImage imageNamed:@"someImage.png"];

//The rest of code is the same 

UPDATE

For case of more than one barItem, define navigation controllers as following:

UINavigationController* firstNavigationController;
UINavigationController* secondNavigationController;
UINavigationController* thirdNavigationController;

firstNavigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController]; 
firstNavigationController.tabBarItem.image = [[UIImage imageNamed:@"someImage1.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

secondNavigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController]; 
secondNavigationController.tabBarItem.image = [[UIImage imageNamed:@"someImage2.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

thirdNavigationController = [[UINavigationController alloc] initWithRootViewController:thirdViewController]; 
thirdNavigationController.tabBarItem.image = [[UIImage imageNamed:@"someImage3.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top