Swift 更改SFSafariViewController的栏颜色

Swift 更改SFSafariViewController的栏颜色,swift,Swift,我正在演示一个SFSafariViewController,试图更改顶部导航栏的颜色,并且在UIViewController中显示视图时找到了资源;但是,我在UICell中演示它:例如 viewController?.present(SFSafariViewController(url: URL(string: "https://apple.com")!), animated: true, completion: nil) 更改顶部条形图色调的正确方法是什么?这就是我所指的: 您可以尝试以下

我正在演示一个SFSafariViewController,试图更改顶部导航栏的颜色,并且在UIViewController中显示视图时找到了资源;但是,我在UICell中演示它:例如

viewController?.present(SFSafariViewController(url: URL(string: "https://apple.com")!), animated: true, completion: nil) 
更改顶部条形图色调的正确方法是什么?这就是我所指的:

您可以尝试以下方法:

let vc = SFSafariViewController(url: URL(string: "https://apple.com")!)
vc.preferredBarTintColor = .red
self.present(vc, animated: true, completion: nil)

如果您想更改条形图颜色以及控件(按钮)颜色,可以尝试以下代码

private func presentWebBrowser(with  url : String){
        if let url = URL(string: url) {

        let vc = SFSafariViewController(url: url)
        vc.preferredBarTintColor = .magenta
        vc.preferredControlTintColor = .white
        self.present(vc, animated: true, completion: nil)
        } else {
            print("URL not correct")
        }
    }