3

I want to put online image on tab bar item.

Is this possible in iOS?

enter image description here

wagng
  • 691
  • 2
  • 11
  • 22

2 Answers2

2

You can use WebImage and load it by using SDWebImage.

https://github.com/rs/SDWebImage

So once it load and you get the object of UIImage inside its method you can check UIImage object should not be nil If not nil then set that UIImage to your tabbar Item Image.

imageView.sd_setImageWithURL(NSURL(string: urlString), completed: {
            (image, error, cacheType, url) in
            // Change tabbar item image here....

           tabHome.image=image?.withRenderingMode(.alwaysOriginal) // deselect image
           tabHome.selectedImage = image?.withRenderingMode(.alwaysOriginal) // select image


        })

Reference: how to set image in a tab bar item in swift?

Mr.Javed Multani
  • 12,549
  • 4
  • 53
  • 52
  • Thanks Man. This Question and Answer both helped me in an unexpected way. Sometimes, It only requires a line or two to enlighten the code. :) – iHarshil Feb 12 '19 at 09:56
0

This is possible in iOS via UITabBarItem You need to select UITabBarItem constructor for your business and set the image

UITabBarItem(title: String?, image: UIImage?, selectedImage: UIImage?)
UITabBarItem(title: String?, image: UIImage?, tag: Int)
Emre Ozdil
  • 401
  • 6
  • 12