【问题标题】:SFSafariViewController title color changeSFSafariViewController 标题颜色变化
【发布时间】:2018-12-14 11:53:50
【问题描述】:

我在 iphone 中使用 SFSafariViewController 显示网站我想像我的应用一样更改配色方案,我想更改顶部 SFSafariViewController 标题的颜色。

【问题讨论】:

标签: ios sfsafariviewcontroller


【解决方案1】:
import SafariServices

extension UIViewController {

    /// Safari Service ViewController with
    /// - parameter link: initial load url
    func openSafariService(withURL link: String) {

        //  let url = link.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)

        if link.isNotBlank {
            let safariVC = SFSafariViewController(url: URL(string: link)!, entersReaderIfAvailable: true)
            safariVC.preferredBarTintColor = UIColor.themeBlue
            safariVC.preferredControlTintColor = UIColor.white
            self.present(safariVC, animated: true, completion: nil)
        }

    }
}

// Update navigation bar
func updateNavigationBar() {
     navigationController?.navigationBar.barTintColor = UIColor.themeBlue
     navigationController?.navigationBar.tintColor = UIColor.white
     navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white,
                                                                       NSAttributedStringKey.font: UIFont.customFont(size: 17.0)]
}

我更新了我的导航栏,然后我调用我的 safariService 函数,它对我来说工作正常。

【讨论】:

    【解决方案2】:

    不,您不能更改 SFSafariViewController 的 URL“标题”颜色。它是您网页的默认视图。如果您想要自定义,您可以使用WKWebView

    【讨论】:

      【解决方案3】:

      试试这个

      UINavigationBar.appearance().backgroundColor = UIColor.green
      UINavigationBar.appearance().tintColor = UIColor.red
      let attrs = [
            NSForegroundColorAttributeName: UIColor.red
      ]
      UINavigationBar.appearance().titleTextAttributes = attrs
      

      来源:https://github.com/zendesk/zendesk_sdk_chat_ios/issues/130

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-06
        • 2016-08-31
        相关资源
        最近更新 更多