我的应用程序的文档目录中有一堆图像。我想在我认为的 UIImage 中加载其中一个。这就是我所做的:
myImage.image = UIImage(named: "image.jpg") // the file exist but this returns nil
Run Code Online (Sandbox Code Playgroud)
我还尝试使用以下方法初始化图像:
myImage.image = UIImage(contentsOfFile: imagePath) //this also doesn't work but the path i got starts (at least in the sim) with file://
Run Code Online (Sandbox Code Playgroud)
任何人都可以提出建议吗?我是 iOS 编程的菜鸟。
谢谢
编辑: imagePath 来自:
func getImgPath(name: String) -> String
{
let documentsDirectory = self.getDocumentsDirectory()
let fullpath = documentsDirectory.appendingPathComponent(name)
return fullpath.absoluteString
}
Run Code Online (Sandbox Code Playgroud)