简体   繁体   English

如何将 WKWebview 颜色更改为白色

[英]How to change WKWebview Color to white

I am using WKWebview .我正在使用WKWebview I want to change it's background to .white.我想将它的background更改为.white. i tried -我试过了 -

  wkWebView.backgroundColor = .white
  wkWebView.scrollView.backgroundColor = .white
  view.backgroundColor = .white

But it's not showing white background.但它没有显示白色背景。

Not quite an answer (but not enough rep to comment).不完全是一个答案(但没有足够的代表发表评论)。

What I usually do to debug is set very odd colours to things to see what is actually being set, eg yellow, pink, blue.我通常做的调试是为事物设置非常奇怪的颜色,以查看实际设置的内容,例如黄色、粉色、蓝色。 This way you can assess if the colour change you're trying to make is working, as well as breakpoints to make sure the line is getting called:)通过这种方式,您可以评估您尝试进行的颜色更改是否有效,以及断点以确保调用该行:)

What worked for me was:对我有用的是:

webView.backgroundColor = .white

Try the following:尝试以下操作:

set view background to white将视图背景设置为白色

view.backgroundColor = .white

set WKWebView background to non-opaque & clear将 WKWebView 背景设置为非透明和清晰

wkWebView.backgroundColor = .clear
wkWebView.opaque = false

This will essentially make the webview see-thru (at least until it loads its own HTML content) and the background view will be visible.这实际上将使 webview 透明(至少在它加载自己的 HTML 内容之前)并且背景视图将可见。

A similar trick will help with dark mode support to avoid the white flash that occurs, but set view.backgroundColor =.systemBackgroundColor类似的技巧将有助于暗模式支持以避免出现白色 flash,但设置view.backgroundColor =.systemBackgroundColor

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM