macOS WKWebView背景透明度

Iva*_*lov 1 macos swift wkwebview

如果有人有经验WKWebView,请分享如何使视图的背景透明.该WebView对象有这样的选项,var drawsBackground: Bool { get set }但它缺少WKWebView类.我在网上搜索了......什么都没发现.在时间之前,可以通过opaque财产这样做,但现在不行了.有吸气剂isOpaque......就是这样.我不想通过CSS来做,并且已经尝试了其他所有内容,例如:

webview.wantsLayer = true

webview.layer?.backgroundColor = NSColor.clear.cgColor

如果有人可以帮忙......

I. Nikolov

Ely*_*Ely 6

这适用于macOS 10.11和macOS 10.12:

if NSAppKitVersion.current.rawValue > 1500 {
    webView.setValue(false, forKey: "drawsBackground")
}
else {
    webView.setValue(true, forKey: "drawsTransparentBackground")
}
Run Code Online (Sandbox Code Playgroud)

备注:这已通过App Store审核.