简体   繁体   中英

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:

首次显示视图时的屏幕截图

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM