Swift实现截屏并保存相册

 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)
}
}

  

swift3  截屏

 func getScreenImage() -> UIImage {
//截屏
let screenRect = UIScreen.main.bounds
UIGraphicsBeginImageContext(screenRect.size)
let ctx:CGContext = UIGraphicsGetCurrentContext()!
self.view.layer.render(in: ctx)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext();
return image!
}
上一篇:CentOS 7.4 安装 网易云音乐


下一篇:用vuejs仿网易云音乐(实现听歌以及搜索功能)