UIBittu
UIBittu

Reputation: 215

UITabbar item image is not shown properly

UITabbar item's image tint color is grey(default) when the view appear for the first time before user select one tab.

Screen shot when the view appear for the first time:

screen shot when the view appear for the first time

Upvotes: 0

Views: 271

Answers (1)

lucgian841
lucgian841

Reputation: 2002

I had the same issue and I solved by inserting the UITabBar item with this code:

UITabBar *tabBar = self.tabBarController.tabBar;
    UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
    UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
    UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];

    tabBarItem1.image = [[UIImage imageNamed:@"img1.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem2.image = [[UIImage imageNamed:@"img2.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem3.image = [[UIImage imageNamed:@"img3.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    tabBarItem1.selectedImage = [[UIImage imageNamed:@"img1_sel.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

I added this code to all my view controller (in my case 3) and it create the right image, while selected and not selected. I hope it helps you

Upvotes: 1

Related Questions