2

I have a ScrollView within which I am adding TextViews, ImageViews and a UIWebView. I am able to dynamically adjust the height of all these views except the UIWebView.

I have turned off the scrolling of the UIWebView, and want to resize the WebView according to its content. And at the same time resize the scrollview according to the resized WebView.

The scrollview should contain the resized WebView. I think there is much discussion about and around this but I haven't been able to reach a concrete solution. So any help would be appreciated.

4

1 回答 1

0

这是你可以尝试的

在 UIWebView 中加载内容后,您可以使用它的stringByEvaluatingJavaScriptFromString:方法来询问 html 文档的高度。这有点棘手,但应该可以。

你可以这样做:

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

scrollheight应该不是最好的。你有几个选择。试用 http://james.padolsey.com/javascript/get-document-height-cross-browser/中提到的文档属性

之后你可以scrollview根据内容调整你的大小,

到目前为止,这是唯一可行的方法。祝你好运

于 2013-08-08T08:40:27.663 回答