码迷,mamicode.com
首页 > 编程语言 > 详细

Swift实现截屏并保存相册

时间:2016-10-12 19:18:18      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

 func saveToLocal() {
        //截屏
        let screenRect = UIScreen.mainScreen().bounds
        UIGraphicsBeginImageContext(screenRect.size)
        let ctx:CGContextRef = UIGraphicsGetCurrentContext()!
        self.view.layer.renderInContext(ctx)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext();
        
        //保存相册
        UIImageWriteToSavedPhotosAlbum(image!, self, "image:didFinishSavingWithError:contextInfo:", nil)
        
    }
    
    func image(image:UIImage,didFinishSavingWithError error:NSError?,contextInfo:AnyObject) {
        
        if error != nil {
            K12ProgressHUD.showError("保存失败", view: self.view)
        } else {
            K12ProgressHUD.showSucess("保存成功", view: self.view)
        }
    }

  

Swift实现截屏并保存相册

标签:

原文地址:http://www.cnblogs.com/yajunLi/p/5953966.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!