facebook twitter hatena line email

Ios/swift/画像保存

提供: 初心者エンジニアの簡易メモ
2016年8月1日 (月) 10:05時点におけるAdmin (トーク | 投稿記録)による版

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
移動: 案内検索

画像保存

       let ac = UIAlertController(title: "画像保存", message: "この画像を保存しますか?", preferredStyle: .Alert)
       let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) -> Void in}
       let okAction = UIAlertAction(title: "OK", style: .Default) { (action) -> Void in
           UIImageWriteToSavedPhotosAlbum(self._imageView.image!, self, #selector(self.image(_:didFinishSavingWithError:contextInfo:)), nil)
       }
       ac.addAction(cancelAction)
       ac.addAction(okAction)
       presentViewController(ac, animated: true, completion: nil)
   func image(image: UIImage, didFinishSavingWithError error: NSError!, contextInfo: UnsafeMutablePointer<Void>) {
       var title:String = "保存完了"
       var message:String = "アルバムへの保存完了"
       if error != nil {
           title = "エラー"
           message = "アルバムへの保存に失敗しました"
       }
       let alert:UIAlertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
       alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: {
           (action) -> Void in
           print("ok")
       }))
       self.presentViewController(alert, animated: true, completion: {})
   }

参考:http://swift-studying.com/blog/swift/?p=473