I have a method I use to get images from a various views in my iOS application for letting users email screens. Most of the screens where I draw are working ok, but when I u
I created a category for this a while ago. It works if (and only if) the web view is cached into memory, otherwise parts of the page will appear as white.
#import "UIWebView+Screenshot.h"
#import
@implementation UIWebView (Screenshot)
- (UIImage *)screenshot {
UIImage *img = nil;
UIGraphicsBeginImageContextWithOptions(self.scrollView.contentSize, self.scrollView.opaque, 0.0);
{
CGPoint savedContentOffset = self.scrollView.contentOffset;
CGRect savedFrame = self.scrollView.frame;
self.scrollView.contentOffset = CGPointZero;
self.scrollView.frame = CGRectMake(0, 0, self.scrollView.contentSize.width, self.scrollView.contentSize.height);
[self.scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];
img = UIGraphicsGetImageFromCurrentImageContext();
self.scrollView.contentOffset = savedContentOffset;
self.scrollView.frame = savedFrame;
}
UIGraphicsEndImageContext();
return img;
}
@end