在swift 4.2中加载动态html页面时,如何在iOS上为wkWebview实现本地自定义字体?
首先,我在web部件中创建了我的style.css在swift 4.2中加载动态html页面时,如何在iOS上为wkWebview实现本地自定义字体?,html,ios,swift,fonts,wkwebview,Html,Ios,Swift,Fonts,Wkwebview,首先,我在web部件中创建了我的style.css @font-face { font-family: "Noto Sans Southeast Asian"; font-weight: normal; src: local("Noto Sans Southeast Asian"), url("NotoSansSoutheastAsian-Regular.ttf") format("truetype"); } @font-face { font-family: "Noto San
@font-face {
font-family: "Noto Sans Southeast Asian";
font-weight: normal;
src: local("Noto Sans Southeast Asian"), url("NotoSansSoutheastAsian-Regular.ttf") format("truetype");
}
@font-face {
font-family: "Noto Sans Southeast Asian Bold";
font-weight: bold;
src: local("Noto Sans Southeast Asian Bold"), url("NotoSansSoutheastAsian-Bold.ttf") format("truetype");
}
我已经完成了本机iOS部分的说明
它不起作用
我得到的建议是,如果我想动态生成HTML页面,我必须将HTML页面编码为base64,然后将其转换为本机部分,为wkWebview添加本地字体
我不知道如何实现wkWebview,以便在项目从Html文件加载的每个页面中使用自定义字体
我从wkWebview开始。
我的项目使用swift 4.2
func updateHTMLStringStyle(fontSize: String, bodyContent: String) -> String {
return "<html><head><meta charset='utf-8'><meta name='viewport' content='width=device-width, initial-scale=1, shrink-to-fit=no'><meta name='theme-color' content='#000000'><meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' /><meta name='theme-color' content='#000000'><meta name='msapplication-navbutton-color' content='#5A9C14'><meta name='apple-mobile-web-app-status-bar-style' content='#000000'><style>a:link { color: blue; }</style><link href='https://fonts.googleapis.com/css?family=ProximaNova-Regular' rel='stylesheet'><style>:root,* {font-family: ProximaNova-Regular;font-size: \(fontSize);color: "rgb(216, 216, 216)");text-align: left;-webkit-user-select: none;user-select: none;}</style></head><body>\(bodyContent ?? "")</body></html>"
}
我希望,这将是有效的。对于我的情况
我通过在我的style.css中编辑web部件来解决这个问题,并将WOFF字体类型上传到我的网站,然后链接到它
我刚刚知道iOS safari从iOS 10开始就支持WOFF和WOFF2*
@font-face {
font-family: "Noto Sans Southeast Asian";
src: local("Noto Sans Southeast Asian"),
url(LINK_TO_FONT/NotoSansSoutheastAsian-Regular.woff) format("woff");
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: "Noto Sans Southeast Asian Bold";
src: local("Noto Sans Southeast Asian Bold"),
url(LINK_TO_FONT/NotoSansSoutheastAsian-Bold.woff) format("woff");
font-weight: bold;
font-style: normal;
}
谢谢你们,对于我的情况,我的目的是使所有的html文件,从网站加载更改为我的自定义字体的字体。您的答案只是使用本地字体创建静态页面。我试过你的答案,但对我的情况不起作用
@font-face {
font-family: "Noto Sans Southeast Asian";
src: local("Noto Sans Southeast Asian"),
url(LINK_TO_FONT/NotoSansSoutheastAsian-Regular.woff) format("woff");
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: "Noto Sans Southeast Asian Bold";
src: local("Noto Sans Southeast Asian Bold"),
url(LINK_TO_FONT/NotoSansSoutheastAsian-Bold.woff) format("woff");
font-weight: bold;
font-style: normal;
}