gpt4 book ai didi

html - 在swift 4.2中加载动态html页面时,如何在iOS上实现wkWebview的本地自定义字体?

转载 作者:行者123 更新时间:2023-11-29 05:14:03 24 4
gpt4 key购买 nike

首先,我在 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 Sans Southeast Asian Bold";
font-weight: bold;
src: local("Noto Sans Southeast Asian Bold"), url("NotoSansSoutheastAsian-Bold.ttf") format("truetype");
}

我已经完成了 native iOS 部分的说明 custom font not working programmatically in swift

没有成功

我收到建议,如果我想动态地生成 HTML 页面,则必须将其编码为 base64,然后将其带到 native 部分以添加 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>"

}

您可以根据您的要求自定义此 HTML 格式的字体样式、文本颜色、字体大小。在上面的函数中传递webview内容和字体大小。

使用函数

webViewBody.loadHTMLString((self.updateHTMLStringStyle(fontSize: "21px"))!, baseURL: nil)

我希望,这会起作用。

关于html - 在swift 4.2中加载动态html页面时,如何在iOS上实现wkWebview的本地自定义字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59370470/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com