【发布时间】:2019-11-30 11:10:36
【问题描述】:
我在资产目录中有一张图片,我需要使用 scale 参数获取这张图片 (UIImage)。只有UIImage(data: scale:) 方法,但我无法使用该名称从资产中获取数据。我总是得到url = nil。可能问题出在目录结构上!?
我的代码:
if let url = Bundle.main.url(forResource: "countdown_photo_1", withExtension: "jpg") {
return UIImage(data: try! Data(contentsOf: url), scale: scale)
}
我的目录结构:
我的 Contents.json:
{
"images" : [
{
"idiom" : "universal",
"filename" : "countdown_photo_1.jpg"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
【问题讨论】: