几天前才开始尝试学习。我的UIImageView
中有一张图片,如何将其保存到图库中?我创建了一个带有IBAction
的按钮
与.pngData()
有关系吗?
谢谢
答案 0 :(得分:1)
@IBAction func nameOfFunctionToSave(_ sender: AnyObject) {
UIImageWriteToSavedPhotosAlbum(imageTake.image!, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
}
extension photoPickerController : UIImagePickerControllerDelegate {
func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
if let error = error {
// in case we get an error
let alert = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default))
present(alert, animated: true)
} else {
// in case of success
let alert = UIAlertController(title: "Saved!", message: "Image saved successfully in your library", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default))
present(alert, animated: true)
}
}