我正在尝试获取作为 Xcode 项目一部分的图标图像的路径,但没有成功。我可以使用名称创建图像,但我需要路径。
let img = Bundle.main.path(forResource: "credit.jpg", ofType:"jpg")
let imm = UIImage(named: "credit.jpg")
我可以看到 img 是 nil 但 imm 不是。
有什么想法吗?
最佳答案
请检查:
图片路径:
let img = Bundle.main.path(forResource: "credit", ofType: "jpg")
print(img!)
图片网址:
let img = Bundle.main.url(forResource: "credit", withExtension: "jpg")
print(img!)
关于ios - 无法从项目包中提取图像路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45133469/