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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 07:21:47  来源:igfitidea点击:

How to load image from Images.xcassets into a UIImage with swift

iosswiftuiimage

提问by David

I have an image from the Images.xcassetsfolder and I want to load it into a UIImageprogrammatically 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!

享受编码!