【问题标题】:Swift - Custom color theme and SFSafariViewControllerSwift - 自定义颜色主题和 SFSafariViewController
【发布时间】:2017-11-12 11:54:06
【问题描述】:

我将自定义颜色应用于多个视图,如下所示:

 let uiView = UIView.appearance()
 uiView.backgroundColor = .black

这会像我预期的那样改变 UIView 颜色,但稍后在应用程序中我触发了 SFSafariViewController。当 SFSafariViewController 出现时,它是全黑的。有没有办法识别视图是 SFSafariViewController 并改变它的颜色?

 let vc = SFSafariViewController(url: targetURL!, entersReaderIfAvailable: true)
 present(vc, animated: true, completion: nil)

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    我认为您将很难通过您的方法 - 更改 UIView 的背景颜色也会更改从 UIView 继承的每个视图的背景颜色,正如您发现的那样,它包括整个 SFSafariViewController - 按钮等等。

    我建议更好的方法是更具体地确定要为其设置背景颜色的视图类型、UIButton、UITabBar 等等。如果您还需要更改实际的 UIView,则可以创建一个子类并在其上设置外观。您的 UIView 子类可以为空:

    class MyCustomView: UIView {
    
    }
    

    然后你可以在这个视图上设置你的外观:

    MyCustomView.appearance().backgroundColor = .black
    

    在 Interface Builder 中,选择您的视图并为其设置自定义类:

    【讨论】:

      【解决方案2】:

      没必要。

      只需使用CSafariWebKit 并在 BarTintColor 和 TintColor 中设置您想要的颜色:

      let vc = SafariViewController(url: url, barTintColor: nil, tintColor: nil)
      vc.presentSafari(fromViewController: self, whenDidFinish: nil)
      

      【讨论】:

        猜你喜欢
        • 2013-06-17
        • 1970-01-01
        • 2016-08-11
        • 2015-10-04
        • 2017-11-29
        • 2018-06-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多