5

I have an application with UITabbar , I want to set image in Tabbar but am unable to set image in Tabbar. Instead of as it is image i get image shape in tint color, Is it possible to set image as it is in Tabbar? .

i have Tried this code but Unable to set image.

UITabBar *tabBar = self.tabBar;

UITabBarItem *targetTabBarItem = [[tabbar items] objectAtIndex:0]; // whichever tab-item
UIImage *selectedIcon = [UIImage imageNamed:@"name-of-selected-image.png"];
[targetTabBarItem setSelectedImage:selectedIcon];
Nirav D
  • 71,513
  • 12
  • 161
  • 183
princ___y
  • 1,089
  • 1
  • 9
  • 27

2 Answers2

23

You need to set your image attributes property Render As to Original Image. To change this select your image from assets and in the Attributes Inspector set Render As property to Original Image like this.

enter image description here

Nirav D
  • 71,513
  • 12
  • 161
  • 183
0

Select your TabBar Item and set your image like this

enter image description here

OR

Set selected tint color try this

[[UITabBar appearance] setTintColor:[UIColor whiteColor]];

    [UITabBarItem.appearance setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]} forState:UIControlStateNormal];
    [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"name-of-selected-image.png"]];
    [[UITabBar appearance]setSelectedItem:[[UITabBar appearance].items objectAtIndex:2]];
Kamlesh Shingarakhiya
  • 2,757
  • 2
  • 16
  • 34