Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change tab bar item image in swift programatically

I am working on an app in Xcode. I currently have three tabBarItems on my tab bar. I want the middle one to be a picture chosen by the user. I have the desired picture in a variable and i have the tabbar.swift set up to put the code in. I just need to set the image to the variables image with correct size (and make the picture appear as a circle) and the title name to a string. Any help in doing this would be much appreciated. Thanks

like image 737
user6520705 Avatar asked Sep 06 '16 22:09

user6520705


1 Answers

Try this code.

    self.tabBarController?.tabBar.items![0].image = UIImage(named: "your image name")
    // items![0] index of your tab bar item.items![0] means tabbar first item

    self.tabBarController?.tabBar.items![0].selectedImage = UIImage(named: "your image name")
like image 121
Sofeda Avatar answered Oct 19 '22 14:10

Sofeda