Using custom fonts in WKWebView

后端 未结 5 575
栀梦
栀梦 2020-11-29 00:15

I\'m using custom fonts in my app. They are copied to bundle and hardcoded to appName-info.plist. This fonts works perfectly in the whole app and in UIWebView.

Im lo

5条回答
  •  天命终不由人
    2020-11-29 00:54

    Assuming you embed the font in your application as a resource that's copied to the target bundle, you can give the WKWebView access to the font by passing a NSURL to it's folder as the baseURL

    NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
    NSURL *bundleUrl = [NSURL fileURLWithPath:bundlePath];
    [self.webView loadHTMLString:HTML baseURL:bundleUrl];
    

    and define the font-face url without any preceeding path elements, which in turn makes WKWebKit prepend the baseURL

    
    

提交回复
热议问题