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
Asked
Active
Viewed 1.4k times
9
-
Include your code, what you have tried, and what problems you are facing. – Michael Sep 07 '16 at 01:01
-
self.tabBarController?.tabBar.items![0].image = UIImage(named: "your image name") self.tabBarController?.tabBar.items![0].selectedImage = UIImage(named: "your image name") – user6520705 Sep 11 '16 at 21:03
-
and both failed – user6520705 Sep 11 '16 at 21:04
1 Answers
14
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")

Sofeda
- 1,361
- 1
- 13
- 23
-
I tried using this code in my tabbar.swift file but it didnt do anything – user6520705 Sep 09 '16 at 15:25
-
2sorry.was in vacation. you are using custom tabbar.swift ? It will work where you want to change the image with the reference of tabBarController. – Sofeda Sep 18 '16 at 05:11