Search code examples
htmliosuiwebview

WKWebView can not load the local HTML with the local front


When I change to use WKWebView to load the local HTML, there are some issues. Due to the auto scaling, I have added the code to the html.

<meta name="viewport" content="initial-scale=1.0" />

For now, the html can be loaded, but the front type is not correct. Obviously, the right one(WKWebView) is not the same with the left one(UIWebView). I use the local front type in the project.

enter image description here enter image description here

I wonder if I need to add something else to load the html with the correct front type. Could you please help me? Thanks in advance.


Solution

  • Scenario:

    WkWebView loading is through string html. WkWebView is using local .css. Fonts are local and are added at top level project. Entries for fonts are provided in appName-info.plist under key Fonts provided by application.

    Solution:

    Add font face in .css at top level as follows

    @font-face
    {
        font-family: 'FontFamily';
        src: local('FontFamily'),url('FontFileName.otf') format('opentype');
    }