Despite trying various methods posted on SO, I was unable to have the simulator display tab bar icons when initialising the tab bar controller.
For each icon, I provided 3 sizes ie 25px by 25px, 50px by 50px (@2x) and 75px by 75px (@3x).
This is how my Tabbar is showing up in the simulator
Below are the Tab and Image attributes respectively
Here is one of my icon at 75px x 75px (@3x)
Can someone please guide me where I am going wrong ?
For Swift 3.0
Set programmatically for selected Tab and un-selected Tab Images
let arrayOfImageNameForSelectedState = ["tabBar_img_1", "tabBar_img_2", "tabBar_img_3"]
let arrayOfImageNameForUnselectedState = ["tabBar_img_1", "tabBar_img_2", "tabBar_img_3"]
if let count = self.tabBar.items?.count {
for i in 0...(count-1) {
let imageNameForSelectedState = arrayOfImageNameForSelectedState[i]
let imageNameForUnselectedState = arrayOfImageNameForUnselectedState[i]
self.tabBar.items?[i].selectedImage = UIImage(named: imageNameForSelectedState)?.withRenderingMode(.alwaysOriginal)
self.tabBar.items?[i].image = UIImage(named: imageNameForUnselectedState)?.withRenderingMode(.alwaysOriginal)
}
}
I finally figured out that the problem was to do with the xcassets
folder. To solve this I created a new xcassets
folder in Xcode.
File > New > Resource > Asset Catalog
.
As shown below I made sure my target application is selected as well.
I dragged and dropped the images from the old xcassets
folder to the new one and all the images were loading.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.