简体   繁体   中英

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

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

在此处输入图片说明

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