How to change SFSafariViewController ToolBar color

Srikanth Adavalli picture Srikanth Adavalli · Feb 11, 2016 · Viewed 7.7k times · Source

Expected Output: I want to change the ToolBar color to Dark Black.

Actual Output: ToolBar is light Grey color.

Here is the code:

let webViewController = SFSafariViewController(URL: url, entersReaderIfAvailable: true)
self.navigationController?.toolbar.barTintColor = UIColor.blackColor()
self.navigationController?.toolbar.tintColor = UIColor.whiteColor()
self.navigationController?.toolbar.barStyle = UIBarStyle.Black
self.navigationController?.pushViewController(webViewController, animated: true)

Answer

Leo Natan picture Leo Natan · Feb 12, 2016

Updated Answer for iOS 10 API

SFSafariViewController now has preferredBarTintColor and preferredControlTintColor properties to control how the toolbars look.


Original Answer

SFSafariViewController renders off-process. You can only change the tint color, but not bar style or bar tint color.

To set the tint color, set the Safari controller's view's tint color like so:

let sfController = SFSafariViewController(URL: url, entersReaderIfAvailable: true)
sfController.view.tintColor = UIColor.redColor()
navigationController?.showViewController(sfController, sender: self)