我想在UIWebView中显示自定义字体.我已经将字体放在"应用程序提供的字体"下的plist中.使用的代码:
UIWebView *webView = [[UIWebView alloc] initWithFrame:myRect];
NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
[webView loadHTMLString:html baseURL:baseURL];
[self addSubview:webView];
Run Code Online (Sandbox Code Playgroud)
其中html是一个NSString,具有以下内容:
<html><head>
<style type="text/css">
@font-face {
font-family: gotham_symbol;
src: local('GOTHAMboldSymbol_0.tff'), format('truetype')
}
body {
font-family: gotham_symbol;
font-size: 50pt;
}
</style>
</head><body leftmargin="0" topmargin="0">
This is <i>italic</i> and this is <b>bold</b> and this is some unicode: э
</body></html>
Run Code Online (Sandbox Code Playgroud)
我正在使用iOS 4.2,因此应该支持TTF.我很欣赏一些实际可行的HTML /代码.
我在我的应用程序中使用自定义字体.它们被复制到bundle并硬编码到appName-info.plist.这种字体在整个应用程序和UIWebView中都能很好地工作.
我正在加载htmlString
[webView loadHTMLString:htmlString baseURL:nil];
我在webView中使用这个字体与css:
fontFamily: fontName
但是,当我尝试使用WkWebView自定义字体无法正常工作时.WkWebView显示随机默认字体.
我尝试使用基本URL中的主束路径加载它并在css中使用font-face - WkWebView仍然显示随机字体.
任何想法如何使自定义字体在WKWebView中工作?
对不起我的英语不好