如何为 SFSafariViewController 中的控件设置自定义字体?

Posted

技术标签:

【中文标题】如何为 SFSafariViewController 中的控件设置自定义字体?【英文标题】:How to set a custom font for controls in SFSafariViewController? 【发布时间】:2019-02-19 21:41:57 【问题描述】:

除了颜色之外,我还没有看到任何自定义 SFSafariViewController 的方法,所以我想知道是否有人找到了解决方法,特别是针对控件的字体。 (Swift 4、ios 12 等)

【问题讨论】:

我认为 SFSafariViewController 并不是所有可定制的。如果您想要更多控制权,您可能需要考虑使用 WKWebView。 【参考方案1】:

SFSafariViewController 主要用于在应用程序中显示网页内容。您可以在 SFSafariViewController 中呈现的页面上实现的自定义级别非常低。 Apple 提到主要使用它来显示您的应用程序的网页。

对于覆盖/自定义网页,您应该使用 WKWebView。它提供的功能将帮助您自定义 html/JS 内容,例如 evaluateJavaScript // 这将为您提供对页面中加载的现有 JS 执行操作的选项

使用 WKWebView,当您在 WKWebView 中加载页面时,您可能会这样做。

webView.loadHTMLString("<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='#5A9C14'><meta name='msapplication-navbutton-color' content='#5A9C14'><meta name='apple-mobile-web-app-status-bar-style' content='#5A9C14'><link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet'><style>:root,* font-family: 'Roboto', sans-serif;font-size: 14px;color: rgb(114, 114, 114);text-align: justify;-webkit-user-select: none;user-select: none;</style></head><body>\(htmlIsi)</body>", baseURL: nil)

【讨论】:

以上是关于如何为 SFSafariViewController 中的控件设置自定义字体?的主要内容,如果未能解决你的问题,请参考以下文章

如何为下拉菜单制作 CSS 边框?

如何为 CAShapeLayer 路径和填充颜色设置动画

iPhone - 如何为图像着色?

如何为 RecyclerView 设置 onItemClickListener? [复制]

WCF - 如何为 NTLM 身份验证配置 netTcpBinding?

如何为 UIToolbar 上的按钮添加滚动?