Get image from documents directory swift

后端 未结 4 648
清酒与你
清酒与你 2020-11-27 13:43

Say I were using this code to save an image to the documents directroy

let nsDocumentDirectory = NSSearchPathDirectory.DocumentDirectory
let nsUserDomainMask         


        
4条回答
  •  眼角桃花
    2020-11-27 14:15

    Swift 2

    If you want to get a file from your document directory in Swift 2:

    let path: String? = NSBundle.mainBundle().pathForResource("imageName", ofType: "png", inDirectory: "DirectoryName/Images")
    let imageFromPath = UIImage(contentsOfFile: path!)!
    self.myImage.image = imageFromPath
    

    Hope that helps somebody

提交回复
热议问题