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)
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)
There are two ways:
let resetPasswordSafari = SFSafariViewController(url: url, entersReaderIfAvailable: true)
resetPasswordSafari.preferredBarTintColor = .mainColor
resetPasswordSafari.preferredControlTintColor = .black
And:
class ResetPasswordSafariViewController: SFSafariViewController {
override init(url URL: URL, entersReaderIfAvailable: Bool) {
super.init(url: URL, entersReaderIfAvailable: entersReaderIfAvailable)
delegate = self
preferredBarTintColor = .blue
preferredControlTintColor = .black
}
}
// MARK: - SFSafariViewControllerDelegate
extension ResetPasswordSafariViewController: SFSafariViewControllerDelegate {
internal func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
controller.dismiss(animated: true)
}
}
Good luck all!
I see no way to change background color of ToolBar, but it is possible to change color of buttons in ToolBar.
[UIBarButtonItem appearance].tintColor = [UIColor whiteColor];
All other changes in appearance, or directly in controller properties, have no effect, as I see.
//To make changes in SFSafariViewController
if let url = URL(string:"https://sandydhumale.business.site") {
let config = SFSafariViewController.Configuration()
config.entersReaderIfAvailable = true
config.barCollapsingEnabled = true
let vc = SFSafariViewController(url: url, configuration: config)
vc.dismissButtonStyle = .close
vc.preferredBarTintColor = .green // Your choice color
vc.preferredControlTintColor = .white // All buttons/items color
self.present(vc, animated: true, completion: nil)
}
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.