挺简单一个东西,分享一下
1、截图
UIImage *getImg = [self screenView:self.view];
UIImageWriteToSavedPhotosAlbum(getImg, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
//截图
- (UIImage*)screenView:(UIView *)view{
CGRect rect = view.frame;
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
//截取包涵导航栏
[self.navigationController.view.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
#pragma mark - 保存截图
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
if (error == nil) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"图片已存入手机相册" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
[alert show];
}else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"保存失败" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
[alert show];
}
}