【发布时间】:2018-09-04 14:36:02
【问题描述】:
关于如何在 object-c 中使用 imageWithContentsOfFile 的例子很多,但是我如何在 Swift 中使用它。 imageView.image = UIImage(imageWithContentsOfFile: imageName)
返回参数标签 '(imageWithContentsOfFile:)' 不匹配任何可用的重载
如果我写:imageView.image = UIImage(contentsOfFile:imageName)
它不显示图像。
(我在 Media.xcassets 中有所有图像存储) 我正在显示很多图像,因此使用 UIImage(named:imageName) 不是一个可行的选择。如何快速获取 contentsOfFile 的功能?
【问题讨论】:
-
你用的是哪个 swift 版本?
-
UIImage(contentsOfFile:)在 Swift 4 中是正确的。但它需要文件 URL,而不是文件名......无论如何:请阅读 Apple 的文档。