美文网首页
Swift3.0保存图片到相册

Swift3.0保存图片到相册

作者: 飞扬跋扈的野草 | 来源:发表于2016-12-03 10:03 被阅读221次

    网上的教程都比较早,分享一下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)
            
            
        }
    
    
    // 提示:参数 空格 参数别名: 类型
        func savedOK(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo: AnyObject) {
            print("---")
            
            // if didFinishSavingWithError != nil {
            if error != nil {
                UIAlertView(title: "错误", message: error?.localizedDescription, delegate: nil, cancelButtonTitle: "确定").show()
    
                return
            }
            print("OK")
            UIAlertView(title: "提示", message: "保存成功", delegate: nil, cancelButtonTitle: "确定").show()
            
        }
    
    

    相关文章

      网友评论

          本文标题:Swift3.0保存图片到相册

          本文链接:https://www.haomeiwen.com/subject/odfcmttx.html