Under iOS12 the following code showed a transparent background in a WKWebView.
However, under iOS13 this is no longer the case - why ? And how to achieve the transparent background back again ?
I tried
@IBOutlet weak var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
webView.scrollView.bounces = false
webView.navigationDelegate = self
let body =
"<html>\n" +
"<head>\n" +
"<style>\n" +
"html { margin: 0; }" +
"body { margin: 0; font-family: Avenir-Light; font-size: 41; color: white; background-color: transparent }\n" +
"a, a:active, a:visited, a:hover { color: #FFED00 }\n" +
"</style>\n" +
"</head>\n" +
"<body>\n" +
article.body +
"</body>\n"
"</html>"
webView.loadHTMLString(body, baseURL: nil)
}
Adding the following does not help...
webView.isOpaque = false
webView.backgroundColor = .clear
And strangely enough, if I set a background-colour other than transparent, then it works:
i.e. by replacing the following, I get a red background:
"body { margin: 0; font-family: Avenir-Light; font-size: 41; color: white; background-color: red }\n"
Why is transparent
not working ??? (I also tried clear
- but no success)