Skip to content

Instantly share code, notes, and snippets.

@srm
Created July 21, 2012 02:39
Show Gist options
  • Save srm/3154285 to your computer and use it in GitHub Desktop.
Save srm/3154285 to your computer and use it in GitHub Desktop.
Getting the height of a UIWebView
-(void)webViewDidFinishLoad:(UIWebView *)webView{
//Get the height of the web view, and change it's size to fit the content it's displaying.
[webView setFrame:CGRectMake(webView.frame.origin.x,
webView.frame.origin.y,
320,
[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"].intValue)];
//Change the scrollview's contentSize to accommodate the new height of the webView.
self.scrollView.contentSize = CGSizeMake(320, webView.frame.size.height+webView.frame.origin.y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment