在 iOS12 下,以下代码在 WKWebView 中显示透明背景。
但是,在 iOS13 下不再是这种情况了 - 为什么?以及如何再次实现透明背景?
我试过了
@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)
}
添加以下内容无济于事...
webView.isOpaque = false
webView.backgroundColor = .clear
奇怪的是,如果我设置透明以外的背景颜色,那么它可以工作:
即通过替换以下内容,我得到一个红色背景:
"body { margin: 0; font-family: Avenir-Light; font-size: 41; color: white; background-color: red }\n"
为什么transparent
不工作???(我也试过clear
- 但没有成功)