3

I've tried all the answers for this similar question to calculate the correct content height of a WKWebView, but the result height is always beyond the actual height that makes a long empty area below the end of the content.

Ways I tried:

  1. webView.eveluateJavaScript()
  2. webView.scrollView.contentSize
  3. WKScriptMessageHandler (get the message.body.valueForKey("body"))

And here's the HTML string I tried to load:

> <html><head><style>img{max-width:100%%;height:auto
> !important;width:auto !important;};</style></head><body
> style='margin:0; padding:0; font-size:[myFontSize];
> font-family:[myFont]; color:[myColor]'>[myHTMLstring]</body></html>

Is there another way to get the correct height of WKWebView?

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

1 Answers1

-1
  1. WKWebView, Set consistency with self.view.frame

2.Try it out,

<html>
 <head>
    <style>
       background-color:purple;
    </style>
 </head>
 <body>
 </body>
</html>

```

Johnny
  • 1,112
  • 1
  • 13
  • 21