简体   繁体   English

如何更改 SFSafariViewController 工具栏颜色

[英]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)

Updated Answer for iOS 10 API iOS 10 API 的更新答案

SFSafariViewController now has preferredBarTintColor and preferredControlTintColor properties to control how the toolbars look. SFSafariViewController现在具有preferredBarTintColorpreferredControlTintColor属性来控制工具栏的外观。


Original Answer原答案

SFSafariViewController renders off-process. SFSafariViewController在进程SFSafariViewController渲染。 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:要设置色调颜色,请像这样设置 Safari 控制器视图的色调颜色:

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.我认为无法更改 ToolBar 的背景颜色,但可以更改 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 //在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)
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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