屏幕截图代码:
原理就是把屏幕上控件的layer渲染到上下文中
- (void)viewDidLoad {
[super viewDidLoad];
//开启上下文
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0);
//获取上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
//把控件上的图层渲染到上下文
[self.view.layer renderInContext:ctx];
//获取上下文中的图片
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
//关闭上下文
UIGraphicsEndImageContext();
//保存图片到相册
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}
以上就是本文的全部内容,希望对大家的学习有所帮助。
注:相关教程知识阅读请移步到IOS开发频道。










