Tab bar item Image not showing - xcode 6

This starts to frustrate me, but when I try to change the images of the tab bar items from these default squares or environment icons to my bespoke images, all I get are the shadows / outlines of my image. It doesn't actually show my image. I don't think image size is an issue, but I am changing the image to the attribute inspector.

Have you guys seen this problem before?

+3


source to share


3 answers


TabBar images are automatically rendered as template images ( Apple Docs ). If you want to avoid this behavior, you can do this:

UIImage *img = //YOUR IMAGE YOU WANT TO SET
img = [img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

      

and now use that to create your tab item.



If you are using asset catalogs, you can also set the render mode in the asset catalog to be able to use it in storyboards ("render" option)

asset catalog

+6


source


UITabBar *tabBar = self.tabBar;
UITabBarItem *targetTabBarItem = [[tabbar items] objectAtIndex:0];
UIImage *selectedIcon = [UIImage imageNamed:@"name-of-selected-image.png"];
[targetTabBarItem setSelectedImage:selectedIcon];

      



Try the above code to set an image for both the selected and unselected tab bar item.

+1


source


You can write below code in AppDelegate.m method

Code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   [[[self.tabBarController.viewControllers objectAtIndex:0] tabBarItem]setFinishedSelectedImage:[UIImage imageNamed:@"firstIconActive.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"firstIconInactive.png"]];

   [[[self.tabBarController.viewControllers objectAtIndex:1] tabBarItem]setFinishedSelectedImage:[UIImage imageNamed:@"secondIconActive.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"secondIconInactive.png"]]; 
}

      

0


source







All Articles