预期输出:我想将工具栏颜色更改为深黑色。
实际输出:工具栏为浅灰色。
这是代码:
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)
更新了 iOS 10 API 的答案
SFSafariViewController
现在具有preferredBarTintColor
和preferredControlTintColor
属性来控制工具栏的外观。
原始答案
SFSafariViewController
呈现进程外。您只能更改色调颜色,而不能更改条形样式或条形色调颜色。
要设置色调颜色,请按如下所示设置 Safari 控制器视图的色调颜色:
let sfController = SFSafariViewController(URL: url, entersReaderIfAvailable: true)
sfController.view.tintColor = UIColor.redColor()
navigationController?.showViewController(sfController, sender: self)
有两种方法:
let resetPasswordSafari = SFSafariViewController(url: url, entersReaderIfAvailable: true)
resetPasswordSafari.preferredBarTintColor = .mainColor
resetPasswordSafari.preferredControlTintColor = .black
和:
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)
}
}
祝大家好运!
我认为无法更改工具栏的背景颜色,但可以更改工具栏中按钮的颜色。
[UIBarButtonItem appearance].tintColor = [UIColor whiteColor];
如我所见,外观或直接在控制器属性中的所有其他更改都没有影响。
//在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)
}