不能改变UITabBarItem。图像:CSI中不支持的像素格式

时间:2021-11-17 21:20:06

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 tabBarImage@2x.png in the Images.xcassets and in the AppDelegate I wrote this:

我试图通过代码改变标签栏中显示的图像。我目前正在使用Swift和Xcode 6 beta 3。我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
}

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:

如果我在模拟器上运行它,它会运行得很好,并在标签栏中显示图像。如果我在我的iPad上运行它(iOS 7.1.1),它不会加载图像,并显示这个奇怪的错误:

 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?

什么好主意吗?可能是什么问题吗?什么是CSI的位图数据?

1 个解决方案

#1


1  

Grr.

嗯……。

It seems to be an iOS 7 issue. It works in iOS 8.

这似乎是iOS 7的问题。它在iOS 8中运行。

Beta 2 generated iOS 7 stuff; no problem.

Beta 2生成ios7;没有问题。

Beta 3 seems to be geared towards iOS 8 only.

Beta 3似乎只针对iOS 8。

I suspect folks trying Swift on iOS 7 are S.O.L.

我怀疑在iOS 7上尝试Swift的人是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.

更新2(2014年7月21日):这个bug在Xcode 6 beta 4中得到修复。

However, Swift seems to be a rather quickly moving target...

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

#1


1  

Grr.

嗯……。

It seems to be an iOS 7 issue. It works in iOS 8.

这似乎是iOS 7的问题。它在iOS 8中运行。

Beta 2 generated iOS 7 stuff; no problem.

Beta 2生成ios7;没有问题。

Beta 3 seems to be geared towards iOS 8 only.

Beta 3似乎只针对iOS 8。

I suspect folks trying Swift on iOS 7 are S.O.L.

我怀疑在iOS 7上尝试Swift的人是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.

更新2(2014年7月21日):这个bug在Xcode 6 beta 4中得到修复。

However, Swift seems to be a rather quickly moving target...

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