3

This is beginning to frustrate me but when i try to change my tab bar item images from those default squares or circle icons to my custom made images all i get are shadows/outline of my image..it doesn't actually show my image. I don't think image size is the problem but I'm changing the image on the attribute inspector.

have you guys seen this problem before?

cc_hey
  • 63
  • 1
  • 11

3 Answers3

6

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

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

and now use this to create your tabbar item.

If you are using asset catalogues you can also set the rendering mode in the asset catalogue to be able to use this in storyboards (The "render as" option)

asset catalogue

Nils Ziehn
  • 4,118
  • 6
  • 26
  • 40
1
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 the image for both selected & unselected tab bar item.

Saurabh Mishra
  • 881
  • 1
  • 8
  • 22
  • im getting a error with this: UITabBar *tabBar = self.tabBar; it says tabBar cannot be found – cc_hey Jun 03 '15 at 11:50
0

You can write below code in AppDelegate.m of 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"]]; 
}
Ashok Londhe
  • 1,491
  • 11
  • 29
Mahesh
  • 956
  • 10
  • 17