SFSafariViewController标题颜色更改

时间:2018-12-14 11:53:51

标签: ios sfsafariviewcontroller

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

enter image description here

3 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

尝试一下

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

答案 2 :(得分:0)

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函数称为对我来说正常工作。

enter image description here