Himanshu
Himanshu

Reputation: 2832

UITabbarItem : - Downloaded image does not show up at Tabbar Item.

I am fetching the image url in the json response from server and downloading image using SdWebimage framework which is downloading fine. But when I set this downloading image object to tabbar item , it does not show the image instead it shows the grey square box there.

Also, tried resizing the image to 30*30 px,checked image at url by putting the image url to browser.

This code I'm using to set my image to tabbaritem.....

myImgView.sd_setImageWithURL(url!, placeholderImage: pImage, options:.HighPriority, completed: { (image, error, cahce, url) in
            tabbarItem.image = image
        })

If anyone could tell me to properly set downloaded image to tabbaritem's icon ?

enter image description here

Upvotes: 4

Views: 1676

Answers (1)

beyowulf
beyowulf

Reputation: 15321

The image is downloading. The problem is the UITabBarItem's only use the alpha component of the image. Since your image is completely opaque it is showing up as a gray square. You can change this behavior by setting the UIRenderingMode of the image to be .AlwaysOriginal. For example:

image = image?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal) 

You can then set image to the tab bar item but it will render like a normal image and may not match your other items if they are using template images.

Upvotes: 4

Related Questions