我有一個webView,其中我顯示html文本。我正在計算webView高度,如下所示。webView動態高度問題
int height = [[_webViewDesc stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"] integerValue];
WebView的實際身體大小是不同的,那麼我得到的。如何獲得webView的實際高度。
我有一個webView,其中我顯示html文本。我正在計算webView高度,如下所示。webView動態高度問題
int height = [[_webViewDesc stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"] integerValue];
WebView的實際身體大小是不同的,那麼我得到的。如何獲得webView的實際高度。
爲了獲得高度,你的webview必須首先加載html字符串。給委託屬性設爲您的WebView對象,並試圖獲得高度以下功能
- (void)webViewDidFinishLoad:(UIWebView *)webView {
int height = [[_webViewDesc stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"] integerValue];
NSLog(@"%d",height);
}
你也可以用以下方法來獲得的WebView
NSLog(@"%f",_webViewDesc.scrollView.contentSize.height);
的高度在其中添加這種方法來獲得高度? – Ankur 2013-03-24 10:14:48
同時分配webView。 – Nirav 2013-03-24 11:22:32