Change bar color of SFSafariViewController

Viewed 69

I'm presenting a SFSafariViewController and am attempting to change the color of the navigation bar at the top, and have found resources when the view is presented in a UIViewController; But, I am presenting it in a UICell: e.g

viewController?.present(SFSafariViewController(url: URL(string: "https://apple.com")!), animated: true, completion: nil) 

What is the correct way to change the bar tint on the top? This is what I'm referring to:

enter image description here

2 Answers

You can try this:

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

If you want to change bar colors as well as controls(Buttons) colors you can try this code

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")
        }
    }

enter image description here

Related