簡體   English   中英

無法獲得uiwebview高度的正確值

[英]Can't get the right value for height of uiwebview

我試圖通過這種方式獲取uiwebview的價值:

            var webview = self.articleContent

            println(webview.frame.size.height)
            // prints 300

            // rendering the webview
            webview.loadHTMLString(articleHtmlContent, baseURL: nil)

            // getting the height of the webview
            var output = webview.stringByEvaluatingJavaScriptFromString("document.body.scrollHeight;")!

            println(output)
            // prints 300 - again

所以看起來我得到的輸出是uiwebview的高度而不是HTML內容的高度。

如何獲得HTML內容的高度?

使用其滾動視圖的內容大小,該視圖將在Web視圖在其UIWebViewDelegate上響應webViewDidFinishLoad后可用,如下所示:

func webViewDidFinishLoad(webView: UIWebView!) {
  CGFloat totalHeight = webview.scrollView.contentSize.height
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM