Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"loadHTMLString" height width issue with WKWebView

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

like image 742
AtulParmar Avatar asked Jan 26 '23 01:01

AtulParmar


1 Answers

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)
like image 158
ishwar lal janwa Avatar answered Jan 28 '23 15:01

ishwar lal janwa