Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WKWebView osx set background color

I have a WKWebView in my view

@IBOutlet weak var htmlWKWebView: WKWebView!

I want to change background color to red. I tried:

htmlWKWebView.wantsLayer = true
htmlWKWebView.layer?.masksToBounds = true
htmlWKWebView.layer?.isOpaque = false
htmlWKWebView.layer?.backgroundColor = NSColor.red.cgColor

Nothing worked. Only this:

htmlWKWebView.setValue(false, forKey: "drawsBackground") made background transparent. But background color not set

like image 931
Arti Avatar asked Jul 19 '17 12:07

Arti


Video Answer


1 Answers

How about using webView.setValue(false, forKey: "drawsBackground") and set color on the view underneath the webview? Use something like: bgColorView.setValue(myBGColor, forKey: "backgroundColor")

like image 123
Jay Koutavas Avatar answered Nov 01 '22 21:11

Jay Koutavas