UIWebView截取整个页面为图片

文章内容

1、截图方法

- (void)screenView:(UIScrollView *)view{
UIGraphicsBeginImageContextWithOptions(CGSizeMake(IPONE_WITDH,view.frame.size.height), YES, 0);     //设置截屏大小
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        CGImageRef imageRef = viewImage.CGImage;
    UIImage *sendImage = [[UIImage alloc] initWithCGImage:imageRef];
    UIImageWriteToSavedPhotosAlbum(sendImage, nil, nil, nil);//保存图片到照片库
} 

2、调用

UIScrollView*rt=self.view.subviews.firstObject;

rt.frame=rt.superview.frame;
CGRect frm=rt.frame;
frm.size.height=_webView.scrollView.contentSize.height;
rt.frame=frm;

[rt.superview layoutIfNeeded];
  
[self  screenView:rt];

发表评论