html - 在 Apple 的 WebKit webView 中加载自定义字体的问题
问题描述
我目前正在通过我的应用程序从 UIWebView 迁移到受支持的 WKWebView。除了一件事 - 字体外,一切都很好。
即使我的 html(我正在加载)根本没有改变,但在使用 UIWebView 的应用程序版本中,自定义字体确实会加载。另一方面,在使用 WKWebView 的应用程序中,所有内容都加载但使用默认字体而不是我正在加载的自定义字体。
WebKit 中的此功能是否存在已知问题?
编辑: 更改源 URL 后,字体会加载。但字体粗细不会因变量而异,如您在下面添加的 HTML 代码中所见。
我在 UIWebView 应用程序和 WKWebView 应用程序中都使用了相同的代码:
NSString *strTemplateHTML = [NSString stringWithFormat:@"<html><head>%@<style>%@</style><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"></head><body style=''>%@</body></html>",[self getAdsScript], styles, self.firstPartArticleContent];
[self.articleWebView loadHTMLString:strTemplateHTML baseURL:NSBundle.mainBundle.bundleURL];
的HTML:
body {
margin:0;
padding:0;
font-family:'Heebo';
font-size:%ldpx !important;
direction: rtl;
width: 100%%;
box-sizing: border-box;
}
@font-face {
font-family: 'Heebo';
font-style: normal;
font-display: swap;
src: url(https://fonts.gstatic.com/s/heebo/v12/NGS6v5_NC0k9P9H0TbFhsqMA6aw.woff2) format('woff2');
unicode-range: U+0590-05FF, U+20AA, U+25CC, U+FB1D-FB4F;
}
img {
max-width:100%%;
max-height: none;
height:auto;
width:100%%;
box-sizing: border-box;
}
iframe {
max-width: 100%%;
max-height: none;
width: 100%%;
box-sizing: border-box;
}
a{
color: #5da1c9;
white-space: pre-wrap;
word-wrap: break-word;
}
.OUTBRAIN a {
white-space: initial;
}
.articlelink {
color: #32AE7B;
font-size:%ldpx;
font-family:'Heebo';
font-weight:700;
}
.streamerPositive {
color:#34eb7a;
font-family:'Heebo';
font-weight:500;
}
.streamerNeutral {
color:#9FA6A1;
font-family:'Heebo';
font-weight:500;
}
.streamerNegative {
color:#d41717;
font-family:'Heebo';
font-weight:500;
};
解决方案
推荐阅读
- jolt - 需要 JOLT 规范文件来传输复杂的 JSON
- c - 在 C 中的文本文件中读取并存储 int 之后的 x 字符串
- angular - Karma、Angular 7 和 FontAwesome 问题无法绑定到“icon”,因为它不是“fa-icon”的已知属性
- python-3.x - 找到每个索引的每列的第一个非空出现的最佳方法?
- html - 位置:相对破坏背景剪辑:文本
- javascript - 如何明确设置双向文本的方向性,以便在两种冲突语言一起使用时正确显示?
- java - 每次使用具有不同排序属性的 compareTo() 方法
- python - 如果输入满足来自不同行中不同列的多个条件,如何从列中选择输入?
- amazon-web-services - 如何在另一个 AWS 账户中将 RecordSet 插入到 Route53
- javascript - 如何将 FlatList 文本项复制到剪贴板 onPress