EJZ
EJZ

Reputation: 1256

Change bar color of SFSafariViewController

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

Upvotes: 2

Views: 233

Answers (2)

Jawad Ali
Jawad Ali

Reputation: 14397

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

Upvotes: 0

Kasım Özdemir
Kasım Özdemir

Reputation: 5634

You can try this:

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

Upvotes: 1

Related Questions