macOS WKWebView背景透明 [英] macOS WKWebView background transparency

查看:351
本文介绍了macOS WKWebView背景透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果某人有使用WKWebView的经验,请分享如何使视图背景透明. WebView对象通过var drawsBackground: Bool { get set }具有这样的选项,但WKWebView类却没有.我在网上搜寻,却一无所获.在此之前,可以通过opaque属性来执行此操作,但是现在不再可以了.有一个吸气剂isOpaque ...就是这样.我不想通过CSS进行操作,而已经尝试了其他所有方法,例如:

If someone has experience with WKWebView, please share how to make the background of the view transparent. The WebView object has such option via var drawsBackground: Bool { get set } but it is missing for the WKWebView class. I searched the net and .. found nothing. Before time it was possible to do so via opaque property, but not anymore. There is a getter isOpaque ... and that's it. I don't want to do it via CSS and already tried everything else, like:

webview.wantsLayer = true

webview.wantsLayer = true

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

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

如果有人可以帮助...

If someone can help ...

I.尼科洛夫

推荐答案

这同时适用于macOS 10.11和macOS 10.12:

This should work for both macOS 10.11 and macOS 10.12:

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

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

Remark: this has been passed by App Store review.

这篇关于macOS WKWebView背景透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆