0

I tried several methods to detect whether a UIWebView did load every content from the source like this one and this one.

Here're some typical HTML string to be loaded with UIWebView:

<p>some string</p>
<p><img alt="" src="/path/image.png" /></p>
...something like above 

The below method is always firing too soon before all content (not only the text) that I couldn't get the correct height of the UIWebView. (height is shorter than what the webView actually is)

func webViewDidFinishLoad(webView: UIWebView) {
    // tried to get the content height
    if webView.stringByEvaluatingJavaScriptFromString("document.readyState") == "complete" {
      let height = webView.stringByEvaluatingJavaScriptFromString("document.body.offsetHeight")!
  }
}

Where could I get the correct height of the content?

Community
  • 1
  • 1
bluenowhere
  • 2,683
  • 5
  • 24
  • 37

1 Answers1

0

Have you tried this?

let height = webview.scrollview.contentSize.height
Nilo0f4r
  • 168
  • 2
  • 12