简体   繁体   English

为什么UITabBar中显示的图像在所选项目上显示不正确?

[英]Why image shown in UITabBar, on selected item, not properly?

I have an UITabBar and set 2 images for a tab(active item, deactive item). 我有一个UITabBar并为选项卡(活动项目,非活动项目)设置2张图像。 On deactive item tab icon shown properly as: 在停用项选项卡上的图标正确显示为:

Image here 图片在这里

but when those item is active, icon not shown properly: 但是当这些项目处于活动状态时,图标将无法正确显示:

Image here 图片在这里

Can anyone help me to fix it? 谁能帮我修复它? I was that it will colour just borders of the icon, not entirely 我是说它只会为图标的边框着色,而不是全部着色

You need to use UIImageRenderingMode for that. 您需要为此使用UIImageRenderingMode。

        UIImage *imgNormal=[UIImage imageNamed:@"normal.png"];
        imgNormal=[imgNormal imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

        UIImage *imgSelected=[UIImage imageNamed:@"active.png"];
        imgSelected=[imgSelected imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        tabBarItem.image = imgNormal; 
        tabBarItem.selectedImage = imgSelected;

Hope it helps :). 希望能帮助到你 :)。

  • Check this screenshot: At right side of the screen see 'Rendered as' text and select drop down and use Original image. 检查此屏幕截图:在屏幕右侧,看到“渲染为”文本,然后选择下拉菜单并使用原始图像。 Your problem would be solved. 您的问题将得到解决。 Hope this helps.. 希望这可以帮助..

在此处输入图片说明

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

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