简体   繁体   中英

How to change WKWebview Color to white

I am using WKWebview . I want to change it's background to .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.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.

A similar trick will help with dark mode support to avoid the white flash that occurs, but set view.backgroundColor =.systemBackgroundColor

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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