UIImage不使用Swift显示 [英] UIImage not displaying using Swift

查看:77
本文介绍了UIImage不使用Swift显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用Swift编写的用于显示UIImages的代码可以在iOS 8.0模拟器中运行,但不能在运行IOS 7.0的手机上运行。

Code written in Swift for displaying UIImages works in the iOS 8.0 simulator but not on a phone running IOS 7.0 for some reason.

let image1 = UIImage(named: "img1")
let imageview = UIImageView(image: image1)
self.view.addSubview(imageview)

let image2 = UIImage(named: "img2")
let button = UIButton(frame: CGRect(origin: CGPoint(x: 0, y: 100), size: image2.size)
button.setImage(image2, forState: UIControlState.Normal)
self.view.addSubview(button)

图像在除了在运行iOS 8的模拟器上之外,正确的大小和有效引用的正确位置,它们只是没有显示。

The images are in the right place with the right size and valid references, they're just not being displayed, except on the simulator running iOS 8.

这对其他人来说是个问题吗?

Is this a problem for anyone else?

编辑:
从Images.xcassets中删除,清理项目并将文件复制到包本身似乎对我有用。

Deleting from Images.xcassets, cleaning the project and copying the files into the bundle itself seems to work for me.

推荐答案

我在iOS 8-Simu中试过你的代码lator和我的iOS 7设备,它做了它应该做的。所以不,在我的情况下,我没有看到问题。

I tried your code in iOS 8-Simulator and on my iOS 7 device and it did what it should do. So no, in my case I don't see a problem.

我将img1更改为img1.JPG(文件名),将img2更改为img2.png。我将图像直接复制到视图控制器所在的文件夹中。

I changed img1 to img1.JPG (name of file) and img2 to img2.png. And I copied the images directly into the folder where the view controller is..

这篇关于UIImage不使用Swift显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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