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
change tab bar item image in swift programatically
Asked Answered
Include your code, what you have tried, and what problems you are facing. –
Minter
self.tabBarController?.tabBar.items![0].image = UIImage(named: "your image name") self.tabBarController?.tabBar.items![0].selectedImage = UIImage(named: "your image name") –
Okinawa
and both failed –
Okinawa
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")
I tried using this code in my tabbar.swift file but it didnt do anything –
Okinawa
sorry.was in vacation. you are using custom tabbar.swift ? It will work where you want to change the image with the reference of tabBarController. –
Rhoden
© 2022 - 2024 — McMap. All rights reserved.