无法更改UITabBarItem.image:CSI中不支持的像素格式 [英] Can't change UITabBarItem.image: Unsupported pixel format in CSI

查看:161
本文介绍了无法更改UITabBarItem.image:CSI中不支持的像素格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过代码更改标签栏中显示的图像。我目前正在使用Swift和Xcode 6 beta 3.我在Images.xcassets中导入了tabBarImage.png和tabBarImage@2x.png,在AppDelegate中我写了这个:

  func application(application:UIApplication!,didFinishLaunchingWithOptions launchOptions:NSDictionary!) - > Bool {

让mainColor = UIColor(红色:1.0,绿色:91.0 / 255.0,蓝色:84.0 / 255.0,alpha:1.0)
UITabBar.appearance()。barTintColor = mainColor

让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
}

返回true
}

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

  CSI 
中不支持的像素格式无法从csi位图数据创建未切割的图像。

任何想法?它可能是某种错误吗?什么是CSI位图数据呢?

解决方案

Grr。



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



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



Beta 3似乎只面向iOS 8。



我怀疑人们尝试使用Swift iOS 7是SOL



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



更新: 这是测试项目



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



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


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:

    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...

这篇关于无法更改UITabBarItem.image:CSI中不支持的像素格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆