WKWebView osx set background color

Viewed 920

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

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")

Related