如何将WKWebview颜色更改为白色

时间:2020-05-12 11:54:47

标签: ios swift xcode

我正在使用WKWebview。 我想将其background更改为.white. 我试过-

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

但是它没有显示白色背景。

2 个答案:

答案 0 :(得分:0)

答案不完全(但评论不足)。

我通常做的调试工作是为事物设置非常奇怪的颜色,以查看实际设置的内容,例如黄色,粉红色,蓝色。这样,您可以评估您尝试进行的颜色更改是否有效,以及断点以确保该行被调用:)

对我有用的是:

webView.backgroundColor = .white

答案 1 :(得分:0)

尝试以下操作:

将视图背景设置为白色

let a = 'b'; // this is our global `a` declaration

const func = () => {
  let a = 'a'; // here we declare a new `a` inside the scope of `func`

  const alter = () => {
    window.a = 'c'; // modifies the global `a`
  }

  const ver = () => {
    console.log(window.a); // this will log `c`

    /* 
     * This log below will output `a` as it is referencing the first `a`
     * declared along the scope chain, which is in `func` (the outer scope)
     * and it hasn't been modified.
     */
    console.log(a);

  alter();
  ver();
}
func();

将WKWebView背景设置为不透明且清晰

view.backgroundColor = .white

这实际上将使Webview直通(至少直到加载其自己的HTML内容为止),并且背景视图将可见。

类似的技巧将有助于黑暗模式的支持,以避免发生白色闪光,但是设置wkWebView.backgroundColor = .clear wkWebView.opaque = false