I'm trying to change through code the image shown in the tab bar. I'm currently working with Swift and Xcode 6 beta 3. I imported my tabBarImage.png and [email protected] in the Images.xcassets and in the AppDelegate I wrote this:
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
let mainColor = UIColor(red: 1.0, green: 91.0/255.0, blue: 84.0/255.0, alpha: 1.0)
UITabBar.appearance().barTintColor = mainColor
let tabBarController = self.window!.rootViewController as UITabBarController
var tabBarSubcontrollers = tabBarController.viewControllers as [UIViewController]
let tabBarImages = ["tabBarImageOne", "tabBarImageTwo", "tabBarImageThree"]
for index in 0..<(tabBarSubcontrollers.count) {
let tabBarImage = UIImage(named: "\(tabBarImages[index])").imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
let newTabBarItem = UITabBarItem(title: "", image: tabBarImage, selectedImage: tabBarImage)
newTabBarItem.imageInsets = UIEdgeInsetsMake(5.0, 0.0, -5.0, 0.0)
tabBarSubcontrollers[index].tabBarItem = newTabBarItem
}
return true
}
If i run it on the simulator it works just fine and shows the images in the tab bar. If I run it on my iPad (with iOS 7.1.1), it doesn't load the images and shows this bizarre error:
Unsupported pixel format in CSI
Unable to create unsliced image from csi bitmap data.
Any ideas? Could it be some sort of bug? And what is CSI bitmap data anyway?
Grr.
It seems to be an iOS 7 issue. It works in iOS 8.
Beta 2 generated iOS 7 stuff; no problem.
Beta 3 seems to be geared towards iOS 8 only.
I suspect folks trying Swift on iOS 7 are S.O.L.
I have a project that I'll upload to my server that you can mess with.
UPDATE: here's the test project
UPDATE 2 (July 21, 2014): This bug appears to be fixed in Xcode 6 beta 4.
However, Swift seems to be a rather quickly moving target...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With