Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Resize UIWebView to fit content?

I need to be able to resize the height of a UIWebView until all the content is visible.

Is this possible?

like image 212
aryaxt Avatar asked Sep 07 '11 23:09

aryaxt


1 Answers

After you have loaded content in the UIWebView you can use it's stringByEvaluatingJavaScriptFromString: method to ask the html document for its height. This is a little tricky but should work.

You can do something like this:

NSInteger height = [[webView stringByEvaluatingJavaScriptFromString:
    @"document.body.scrollHeight"] integerValue];

The scrollheight mught not be the best. You have a couple of options. Experiment with the document properties mentioned in http://james.padolsey.com/javascript/get-document-height-cross-browser/

like image 155
Stefan Arentz Avatar answered Oct 15 '22 13:10

Stefan Arentz