Transparent background for WKWebView

ios, swift, wkwebview

Solution

For iOS 10+ using Swift:

self.webView = WKWebView()
self.webView!.isOpaque = false
self.webView!.backgroundColor = UIColor.clear
self.webView!.scrollView.backgroundColor = UIColor.clear

Problem

In my app I wish to make the WKWebView with transparent background, so the view behind (an ImageView) can show through as background picture. ``` webView!.opaque = false webView!.backgroundColor = UIColor.clearColor() ``` The code above works fine with UIWebView, but if webView is WKWebView, a white background will be shown. Also tried putting transparent background color in CSS. The result is the same, only works in UIWebView but not WKWebView. Any suggestion?

Original source