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

泪湿孤枕 提交于 2019-12-25 07:30:12

问题


I have an UITabBar and set 2 images for a tab(active item, deactive item). 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


回答1:


  • 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..




回答2:


You need to use UIImageRenderingMode for that.

        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 :).



来源:https://stackoverflow.com/questions/37236168/why-image-shown-in-uitabbar-on-selected-item-not-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!