IOS8 How to set images TabBarItem
It seems like something has changed since iOS8 and now none of my tab bar icons are showing correctly. Most of the time they don't show until the tab is active:
But sometimes they don't show up at all and just give me a blue box (like when I fire a view that spans the whole window):
This is what I did before 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 = @"";
+3
source to share
3 answers
as mentioned, if you look at:
you will notice that this method is deprecated, try changing:
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"paintbrush-white.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"paintbrush-black.png"]];
in
[tabBarItem1 setImage:[[UIImage imageNamed:@"paintbrush-white.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem1 setSelectedImage:[[UIImage imageNamed:@"paintbrush-black.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
You may have image size issues, depends on image size when tested on iPhone 5 and iPhone 6 screen for images @ 2x
+1
source to share