使用XCode 6 / Swift在iOS 7.1中显示的图像 [英] Images not showing in iOS 7.1 with XCode 6 / Swift
问题描述
我有这个ObjC代码:
I have this ObjC code:
[self.myButton setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@-button", self.myObject.name]]
forState:UIControlStateNormal];
这适用于以下组合:
- XCode 5,iOS 7.1
- XCode 6,iOS 7.1
- XCode 6,iOS 8
但是,当我将项目的一个单独的类移植到Swift时 - 这个类与此代码中发生的任何事情无关 - 图像执行不适用于iOS 7.1的XCode 6。它适用于XCode 6和iOS 8.
But when I port one single class of the project to Swift -- a class which is unrelated to anything that is happening in this code -- the images do not display in XCode 6 for iOS 7.1. It does work with XCode 6 and iOS 8.
我完成了将整个项目移植到Swift,现在代码如下:
I finished porting the entire project to Swift, so now the code looks like:
self.myButton.setBackgroundImage(
UIImage(named:self.myObject.name + "-button"),
forState: UIControlState.Normal
)
在iOS 7.1上它仍然不满意。仍然没有图像。 (虽然自定义图标有效。)是的,我知道这只是测试版软件,它可能只是一个bug ......?但我只是想知道是否有人有解决方案或洞察力。
And it's still unhappy on iOS 7.1. Still no images. (The custom icon works, though.) Yes, I know this is just beta software, and it's probably just a bug ... ? But I'm just wondering if anyone has a solution or insight.
我一周前才开始使用XCode和ObjC(惊喜!ObjC现已弃用!),所以它可能是我遗漏了一些东西,但由于它在ObjC和Swift + iOS8中工作,似乎它可能是一个bug。
I only started using XCode and ObjC about a week ago (surprise! ObjC is now deprecated!), so it could be that I am missing something, but since it works in ObjC, and in Swift+iOS8, it seems like it's probably a bug.
推荐答案
我设法通过不使用资产库来存储我的图像来解决这个问题。
I've managed to overcome this by not using Asset Libraries to store my images.
使用旧式命名将图像添加到项目中,例如 Image.png 和 Image@2x.png ,然后在文件名中加载它们没有任何扩展名,如下:
Add your images to the project using the "old style naming", like Image.png and Image@2x.png, then load them without any extensions in the filename, as such:
let myImage = UIImage(named:"Image")
这篇关于使用XCode 6 / Swift在iOS 7.1中显示的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!