4

I am trying to load HTML content to WKWebView, It does not load properly the same as screen height/width, same code is working fine with UIWebView, See the following code

webView.loadHTMLString(htmlString!, baseURL: nil)

HTML string content <style type="text/css"> #container { width: 667px; height: 375px; margin: 0 auto } </style> 667px is screen height and 375px is screen width.

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            <title>Highcharts Example</title>

            <style type="text/css">
                #container {
                    width: 667px;
                    height: 375px;
                    margin: 0 auto
                }
            </style>
            </head>
    <body>
        <script src="https://code.highcharts.com/highcharts.js"></script>

        <div id="container"></div>


        <script type="text/javascript">

            Highcharts.chart('container', {   
                    //Chart code.
                             });
            </script>
    </body>
</html>

What can I do to solve this issue?

enter image description here

AtulParmar
  • 3,835
  • 15
  • 41

1 Answers1

6

Add headerString before your html code and try it Like below

let description = "<p> HTML content <p>"
var headerString = "<header><meta name='viewport' content='width=device-width, 
initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0'></header>"
headerString.append(description)              
self.webView.loadHTMLString("\(headerString)", baseURL: nil)
  • Thanks @ishwarLalJanwa, It's working but, If I set leading and trailing spaces 30 pixels between WKWebView and main view then it will show horizontally scroll, I don't want to scroll then what can I do for this. – AtulParmar Jul 25 '19 at 13:26
  • How can I fit chart exactly to WKWebView (same as WKWebView size) – AtulParmar Jul 25 '19 at 13:33