简体   繁体   中英

Change Safari View Controller Done Button tint?

I can change bottom UI bar with:

UIBarButtonItem.appearance().tintColor = UIColor.redColor()

Can't locate how to do same with top-right "Done" button.

Here's where that works in AppDelegate.swift:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    UIBarButtonItem.appearance().tintColor = UIColor.redColor()

    return true
}

Adding this does not work:

UINavigationBar.appearance().tintColor = UIColor.redColor()

To change de Done button color and also the bottom UI bar you have to set the tintColor property of the SFSafariViewController's view

example:

let webVC = SFSafariViewController(URL: yourURL)
webVC.view.tintColor = UIColor.redColor()

Ismael's answer didn't work in iOS 10 for me. Since iOS 10 SFSafariViewController has a property preferredControlTintColor to set the color of the buttons. Another new property is preferredBarTintColor fyi.

This is my approach in Swift 3:

let svc = SFSafariViewController(url: URL(string: "<YOUR_URL_STRING>")!)

if #available(iOS 10.0, *) {
    svc.preferredControlTintColor = UIColor.red
} else {
    svc.view.tintColor = UIColor.red
}

self.present(svc, animated: true, completion: nil)

添加此工作:

UIButton.appearance().tintColor = UIColor.redColor()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM