小编And*_*rea的帖子

Swift 3 中来自路径或文件名的 UIImage

我的应用程序的文档目录中有一堆图像。我想在我认为的 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)

xcode uiimage ios swift

3
推荐指数
2
解决办法
1万
查看次数

标签 统计

ios ×1

swift ×1

uiimage ×1

xcode ×1