ios 如何快速将 Images.xcassets 中的图像加载到 UIImage 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32152197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to load image from Images.xcassets into a UIImage with swift
提问by David
I have an image from the Images.xcassets
folder and I want to load it into a UIImage
programmatically using swift. How can I do this? Anyone done this before? Please give me some code examples!
我有一个来自Images.xcassets
文件夹的图像,我想UIImage
使用 swift以编程方式将它加载到一个图像中。我怎样才能做到这一点?以前有人做过这个吗?请给我一些代码示例!
回答by Bright Future
Here's my code:
这是我的代码:
@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
imageView.image = UIImage(named: "Apple")
}
I created an image view and displayed an image inside it.
我创建了一个图像视图并在其中显示了一个图像。
Enjoy coding!
享受编码!