2

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

Sawsan
  • 1,096
  • 10
  • 20
  • Did you check, when you added the image, for exact spelling and correct case on the image file name? – Gallymon Mar 13 '14 at 15:36
  • Yes, it's already working on iOS < 7.1 but after updating to iOS 7.1 it disappeared – Sawsan Mar 13 '14 at 16:09
  • You said, "I searched for the problem and I found that I should add selectedImage but it did not work." That made me think that you discovered something required in 7.1 that wasn't required in 7.0 and down? – Gallymon Mar 14 '14 at 10:43
  • 1
    Maybe something to do with this bug: http://stackoverflow.com/questions/22327646/tab-bar-background-is-missing-on-ios-7-1-after-presenting-and-dismissing-a-view – wrtsprt Mar 14 '14 at 14:00
  • @Gallymon I really don't know what happened after the update iOS 7.1 but I fixed the problem, check my answer – Sawsan Mar 14 '14 at 18:47
  • Working code is a good thing! Cheers. – Gallymon Mar 15 '14 at 01:52

1 Answers1

2

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];
Sawsan
  • 1,096
  • 10
  • 20