網(wǎng)上的教程都比較早,分享一下swift3.0的
@IBAction func saveLingfuImage(_ sender: UIBarButtonItem) {
let customImage = UIImage(named: (lingfu?.image)!)
UIImageWriteToSavedPhotosAlbum(customImage!, self, #selector(savedOK(image:didFinishSavingWithError:contextInfo:)), nil)
//UIImageWriteToSavedPhotosAlbum(image!, nil, nil, nil)
}
// 提示:參數(shù) 空格 參數(shù)別名: 類型
func savedOK(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo: AnyObject) {
print("---")
// if didFinishSavingWithError != nil {
if error != nil {
UIAlertView(title: "錯(cuò)誤", message: error?.localizedDescription, delegate: nil, cancelButtonTitle: "確定").show()
return
}
print("OK")
UIAlertView(title: "提示", message: "保存成功", delegate: nil, cancelButtonTitle: "確定").show()
}