我试图通过代码改变标签栏中显示的图像。我目前正在使用Swift和Xcode 6 beta 3。我在Images中导入了tabBarImage.png和tabBarImage@2x.png。xcassets,在AppDelegate中我这样写:
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
}
如果我在模拟器上运行它,它工作得很好,并在标签栏中显示图像。如果我在iPad上运行它(iOS 7.1.1),它不会加载图像,并显示这个奇怪的错误:
Unsupported pixel format in CSI
Unable to create unsliced image from csi bitmap data.
任何想法?会不会是什么虫子?CSI位图数据到底是什么?
这似乎是iOS 7的问题。
Beta 2生成iOS 7的东西;没问题。
Beta 3似乎只针对iOS 8。
我怀疑那些在iOS 7上尝试Swift的人是s.o.l
我有一个项目,我将上传到我的服务器,你可以乱用。
UPDATE:这是测试项目
UPDATE 2(2014年7月21日):这个错误似乎在Xcode 6 beta 4中得到修复。
然而,Swift似乎是一个相当快速移动的目标…