我在我的应用程序文档目录中有一堆图片。我想在我的视图中加载其中的一张图片到UIImage中。这是我的做法:
myImage.image = UIImage(named: "image.jpg") // the file exist but this returns nil
我也尝试使用以下方式初始化图像:
myImage.image = UIImage(contentsOfFile: imagePath) //this also doesn't work but the path i got starts (at least in the sim) with file://
有人能提供建议吗?我在iOS编程方面有些新手。
谢谢。
编辑: imagePath来自于:
func getImgPath(name: String) -> String
{
let documentsDirectory = self.getDocumentsDirectory()
let fullpath = documentsDirectory.appendingPathComponent(name)
return fullpath.absoluteString
}
imagePath
不正确,请发布相关代码。 - Tj3n