Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change SFSafariViewController ToolBar color

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)
like image 956
Srikanth Adavalli Avatar asked Feb 02 '26 07:02

Srikanth Adavalli


1 Answers

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)
like image 95
Léo Natan Avatar answered Feb 04 '26 19:02

Léo Natan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!