4

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

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Himanshu
  • 2,832
  • 4
  • 23
  • 51
  • How did you access the UIImageView instance myImgView? Where are you calling this function from? – paprika Sep 21 '22 at 11:22

1 Answers1

4

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.

beyowulf
  • 15,101
  • 2
  • 34
  • 40