13

预期输出:我想将工具栏颜色更改为深黑色。

实际输出:工具栏为浅灰色。

这是代码:

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)
4

4 回答 4

26

iOS 10 API 的更新答案

SFSafariViewController现在有preferredBarTintColorpreferredControlTintColor属性来控制工具栏的外观。


原始答案

SFSafariViewController呈现关闭进程。您只能更改色调颜色,但不能更改条形样式或条形色调颜色。

要设置色调颜色,请像这样设置 Safari 控制器视图的色调颜色:

let sfController = SFSafariViewController(URL: url, entersReaderIfAvailable: true)
sfController.view.tintColor = UIColor.redColor()
navigationController?.showViewController(sfController, sender: self)
于 2016-02-12T15:27:04.870 回答
5

有两种方法:

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)
  }
}

祝大家好运!

于 2019-01-14T10:55:29.260 回答
0

//在 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)
    }
于 2021-05-26T07:20:39.283 回答
0

我看不到更改工具栏背景颜色的方法,但可以更改工具栏中按钮的颜色。

[UIBarButtonItem appearance].tintColor = [UIColor whiteColor];

如我所见,外观或直接在控制器属性中的所有其他更改均无效。

于 2016-08-13T11:38:38.247 回答