【问题标题】:How to change SFSafariViewController ToolBar color如何更改 SFSafariViewController 工具栏颜色
【发布时间】:2016-05-21 20:15: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)

【问题讨论】:

  • 那么会发生什么。你的代码不工作还是什么?请添加更多详细信息。
  • @Mack 工具条码对 SFSafariViewController 底部没有影响。
  • 你尝试设置 tintcolor 吗?
  • @BlackbirdSR-71 self.navigationController?.toolbar.tintColor = UIColor.whiteColor() 我已经做过了。但它没有任何影响

标签: objective-c iphone swift uitoolbar sfsafariviewcontroller


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    有两种方式:

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

    祝大家好运!

    【讨论】:

    • internal func safariViewControllerDidFinish 是干什么用的?苹果会批准子类SFSafariViewController的应用程序吗?
    • @spnkr 是的,将批准。这是“内部”访问级别的定义: 内部访问使实体可以在其定义模块的任何源文件中使用,但不能在该模块之外的任何源文件中使用。在定义应用或框架的内部结构时,您通常会使用内部访问。
    【解决方案3】:

    iOS 10 API 的更新答案

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


    原答案

    SFSafariViewController 渲染进程外。您只能更改色调颜色,但不能更改条形样式或条形色调颜色。

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

    let sfController = SFSafariViewController(URL: url, entersReaderIfAvailable: true)
    sfController.view.tintColor = UIColor.redColor()
    navigationController?.showViewController(sfController, sender: self)
    

    【讨论】:

    • 我能够更改导航栏的颜色。但我的客户要求是改变工具栏的颜色。
    • @Audi 不可能。向 Apple 提出改进请求。
    • 或者你可以使用 wkwebview 制作你自己的工具栏
    • 确保您没有在其他地方使用appearance 为窗口或所有视图设置色调,否则这将不起作用。
    • 尝试了首选属性,但没有奏效。尝试删除对appearance 的所有调用,但仍然无效。
    【解决方案4】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-10
      • 2021-07-19
      • 2020-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-21
      相关资源
      最近更新 更多