无法更改UITabBarItem.image:CSI中不支持的像素格式

时间:2014-07-08 17:19:54

标签: ios swift

我正在尝试通过代码更改标签栏中显示的图像。我目前正在使用Swift和Xcode 6 beta 3.我在Images.xcassets中导入了tabBarImage.png和tabBarImage@2x.png,在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.

有什么想法吗?可能是某种bug吗?什么是CSI位图数据?

1 个答案:

答案 0 :(得分:1)

格儿。

这似乎是一个iOS 7问题。它适用于iOS 8。

Beta 2生成iOS 7的东西;没问题。

Beta 3似乎仅面向iOS 8。

我怀疑在iOS 7上尝试Swift的人是S.O.L。

我有一个项目,我将上传到我的服务器,你可以搞乱。

更新: here's the test project

更新2(2014年7月21日):此错误似乎已在Xcode 6 beta 4中修复。

然而,斯威夫特似乎是一个快速移动的目标......