Last active
August 18, 2016 08:42
-
-
Save zhaoyswd/6203836 to your computer and use it in GitHub Desktop.
UIWebView+Screenshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://stackoverflow.com/questions/10692221/screenshot-of-an-uiwebview-that-is-not-currently-on-screen"]]]; | |
NSLog(@"webview = %@",self.webView); | |
} | |
- (void)didReceiveMemoryWarning | |
{ | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
- (void)webViewDidFinishLoad:(UIWebView *)webView{ | |
NSLog(@"contentSize = %f %f",webView.scrollView.contentSize.width,webView.scrollView.contentSize.height); | |
webView.frame = CGRectMake(0, 0, webView.scrollView.contentSize.width, webView.scrollView.contentSize.height); | |
UIGraphicsBeginImageContextWithOptions(webView.scrollView.contentSize, NO, 0); | |
[webView.layer renderInContext:UIGraphicsGetCurrentContext()]; | |
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
NSData *data = UIImagePNGRepresentation(image); | |
NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent:@"page.png"]; | |
[data writeToFile:path atomically:YES]; | |
NSLog(@"path = %@",path); | |
} | |
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{ | |
NSLog(@"%s",__func__); | |
} |
After you take that, u could use "self.webView.scrollView.contentOffset = CGPointMake(0, currentOffset);" to scroll your webview down and take other one.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it's wrong,this will not work absolutely