【问题标题】:Use custom local stored font with WKWebView使用带有 WKWebView 的自定义本地存储字体
【发布时间】:2020-10-25 03:09:34
【问题描述】:

我正在使用最新版本的XcodeSwift

我将一个名为Blastimo.ttf 的字体导入到我的Xcode 项目中,方法是将它拖放到Xcode 左侧的文件列表中。

我启用了Target Membership

我添加了Fonts provided by application > Item 0 : Blastimo.ttfInfo.plist

现在我可以使用这种字体,例如标签。这是有效的。

我也想在我的WKWebView 中使用这种字体,如下所示:

let html = """
        <html>
        <body>
        <head>
        <style>
        @font-face
        {
            font-family: 'Blastimo';
            src: local('Blastimo'), url('Blastimo.ttf') format('truetype');
        }
        </style>
        </head>
        <h1 style="font-family:'Blastimo';font-size:50px;">This is my test!</h1>
        </body>
        </html>
        """
        webView.loadHTMLString(html, baseURL: nil)

但这不起作用,标准字体被加载。

html 代码本身使用字体Blastimo.ttf。我在我的网络服务器上对其进行了测试。

但它不适用于WKWebView。我做错了什么?

【问题讨论】:

    标签: ios xcode fonts font-face wkwebview


    【解决方案1】:

    解决方案是替换:

    webView.loadHTMLString(html, baseURL: nil)

    通过

    webView.loadHTMLString(html, baseURL: Bundle.main.resourceURL)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-25
      • 2014-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多