简体   繁体   English

UITabbar项目图像无法正确显示

[英]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. 当用户在选择一个选项卡之前首次显示该视图时,UITabbar项的图像色调颜色为灰色(默认)。

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 item来解决:

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. 我将此代码添加到我的所有视图控制器(在我的情况下为3),并在选择和未选择时创建正确的图像。 I hope it helps you 希望对您有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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