UIWebView - white background before loading content

岁酱吖の 提交于 2019-12-04 03:59:38

So, what I did, is, added:

myWebView.opaque = false
myWebView.backgroundColor = UIColor.clearColor()

and at controller, I unchecked this from "View"

You cannot set background color to your webView.

You should try following steps:

1. write following in your viewDidLoad - Setting delegate and hiding webView.

webView.delegate = self

webView.hidden = YES

2. Write delegate - shouldStartLoadWithRequest - hiding webView when loading starts.

func webView(webView: UIWebView!, shouldStartLoadWithRequest request: NSURLRequest!, navigationType: UIWebViewNavigationType) -> Bool {
webView.hidden = YES
return true;
}

3. Write delegate - webViewDidFinishLoad - Show webView when loading Ends.

func webViewDidFinishLoad(webView: UIWebView!) {
webView.hidden = NO
print("Webview did finish load")
}

Hope this will help you....

You could load your own html document, which uses the color you need.

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    let htmlString = "<html><body bgcolor=\"#ABCDEF\"></body></html>"
    webView.loadHTMLString(htmlString, baseURL: nil)
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!