Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent background WKWebView (NSView)

I am building a Mac application using Swift. Therefor, I want to make a WKWebView transparent, so it shows the text of the loaded HTML, but the background of my underlaying NSWindow is visible. I tried

webView.layer?.backgroundColor = NSColor.clearColor().CGColor;

which hadn't any effect. WKWebView inherits from NSView, but I don't know if this helps.

Another solution would be to insert a NSVisualEffectView as the background of the WebView, but I don't know how to accomplish that, either!

like image 771
danielbuechele Avatar asked Nov 30 '14 08:11

danielbuechele


2 Answers

Use this in macOS 10.12 and higher:

webView.setValue(false, forKey: "drawsBackground")
like image 117
Ely Avatar answered Sep 24 '22 22:09

Ely


It was not supported, then they fixed it:

https://bugs.webkit.org/show_bug.cgi?id=134779

The way to make it transparent is to:

myWebView.opaque = false
like image 30
AJ Venturella Avatar answered Sep 23 '22 22:09

AJ Venturella