简体   繁体   English

Swift-自定义颜色主题和SFSafariViewController

[英]Swift - Custom color theme and SFSafariViewController

I am applying custom colors to several views, like this: 我将自定义颜色应用于多个视图,如下所示:

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

This changes the UIView colors as I expected but later in the app I am triggering a SFSafariViewController. 这将按预期更改UIView颜色,但稍后在应用程序中,我将触发SFSafariViewController。 When SFSafariViewController appears it is all black. 出现SFSafariViewController时,它全为黑色。 Is there a way to identify view is SFSafariViewController and change the color of it? 有没有一种方法可以识别视图是SFSafariViewController并更改其颜色?

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

I think you're going to have a hard time going through with your approach - changing the background colour of UIView changes the background colour of every view that inherits from UIView also, which as you've found includes the whole of SFSafariViewController - buttons and all. 我认为您将很难采用这种方法-更改UIView的背景色也会更改从UIView继承的每个视图的背景色,正如您所发现的那样,它包括整个SFSafariViewController-按钮和所有。

I'd suggest a better approach is to be more specific about which types of views you want to set the background colour for, UIButton, UITabBar and so on. 我建议一种更好的方法是更具体地确定要为UIView,UITabBar等设置背景颜色的视图类型。 If you also have actual UIViews you need to change you could make a subclass and set the appearance on that instead. 如果您还具有实际的UIView,则需要进行更改,您可以创建一个子类并在其上设置外观。 Your UIView subclass can be empty: 您的UIView子类可以为空:

class MyCustomView: UIView {

}

And then you can set your appearance on this view: 然后可以在此视图上设置外观:

MyCustomView.appearance().backgroundColor = .black

In Interface Builder, select your view and set your custom class for it: 在Interface Builder中,选择视图并为其设置自定义类:

自定义视图类

There's no need for that. 没有必要。

Just use CSafariWebKit and set the Color you want in BarTintColor and the TintColor: 只需使用CSafariWebKit并在BarTintColor和TintColor中设置所需的颜色即可:

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

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

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