Reputation: 2282
I'm trying to resize a UIWebView
so that it fits the entire contents of the loaded page. To do this, I get the content height of the webview's scrollview, and set the height of the webview to that value.
For anything with content height over 200, this works just fine, and the view scales to exactly fit the page without any extra space. But with content of height under 200, the webview seems to hit some sort of height floor, and webView.scrollView.contentSize.height
won't return any values under 200. I'm left with a ton of whitespace.
There are a number of posts on this topic, but none seem to cover this particular issue. What is the best way to return the actual content height when that value is under 200?
EDIT: Here's an example of HTML that should render quite short, but ends up being 200pt tall.
<meta name='viewport' content='width=device-width, user-scalable=yes'>
<html>
<head></head>
<body style='font-family:Helvetica neue; font-size:1.0em; color:#181818; -webkit-font-smoothing: antialiased;'><div>
Here's some example content.
<br/></div>
</body>
Upvotes: 1
Views: 1356
Reputation: 1
I was having a similar problem where I was using a javascript call to get the content height and setting the web view's height to that value, but 568 seemed to be the minimum that those methods would return to me. I ended up having to first set my web view's height to 1, and then set the height to the result of the javascript calls.
Upvotes: 0
Reputation: 3496
Please make sure that both your HTML
and BODY
tags do not have a min-height
or height
css styles.
Then, you should take the height using JavaScript. To get the actual height, instead of the scrollable size which is some kind of unknown UIWebView decision.
So [[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.offsetHeight"] floatValue]
would do.
Upvotes: 1