3

It seems something has changed with iOS8 and now none of my tab bar icons are showing up properly. Most of the time they don't show until the tab is active:

enter image description here

But sometimes they don't show up at all and give me just a big blue box (like whenever I dismiss a view that covered the whole window):

enter image description here

This is what I did pre iOS8:

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"paintbrush-white.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"paintbrush-black.png"]];
tabBarItem1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
tabBarItem1.title = @"";
Chase Roberts
  • 9,082
  • 13
  • 73
  • 131

3 Answers3

1

as mentioned, if you take a look at:

https://developer.apple.com/Library/ios/documentation/UIKit/Reference/UITabBarItem_Class/index.html#//apple_ref/occ/instm/UITabBarItem/setFinishedSelectedImage:withFinishedUnselectedImage:

you will notice that this method is deprecated, try to change:

[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"paintbrush-white.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"paintbrush-black.png"]];

to:

[tabBarItem1 setImage:[[UIImage imageNamed:@"paintbrush-white.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem1 setSelectedImage:[[UIImage imageNamed:@"paintbrush-black.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

You may also have problems with the image size, depends of the size of image when testing in iPhone 5 screen and iPhone 6 screen for @2x images

Fernando
  • 1,323
  • 2
  • 12
  • 17
0

Did you try setSelectedImage:?

UIImage *image = [UIImage imageNamed:@"img.png"] [tabItem setSelectedImage:image];

It works on my part.

eNeF
  • 3,241
  • 2
  • 18
  • 41
-1

This method is deprecated in iOS 8:

Use initWithTitle:image:selectedImage: or the image and selectedImage properties along with UIImageRenderingModeAlwaysOriginal

Michaël
  • 6,676
  • 3
  • 36
  • 55
  • I haven't been able to find anything that says that it is deprecated. Also setting the image and selectedImage attributes don't work. – Chase Roberts Sep 27 '14 at 00:49