-2

Need to Remove Whitescreen before loading webview in iOS, tried webview opaque. Even after adding Splash Screen & launch screen, I'm still getting the white splash before LOADING Webview URL.

import UIKit
import WebKit
class HomeViewController: UIViewController, WKUIDelegate {
    
    var webView: WKWebView!
     
    override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self        
        view = webView
        webView.isOpaque = false
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.translatesAutoresizingMaskIntoConstraints = false
        let myURL = URL(string:"https://google.com")
        let myRequest = URLRequest(url: myURL!)
        

        
        view.addSubview(webView)
        webView.load(myRequest)

        NSLayoutConstraint.activate([
            webView.topAnchor.constraint(equalTo: view.topAnchor),
            webView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
            webView.leftAnchor.constraint(equalTo: view.leftAnchor),
            webView.rightAnchor.constraint(equalTo: view.rightAnchor)
        ])}
}
gajuu
  • 1
  • 3
  • 1
    One problem is that your code contains two different web views! One of them is created later and covers up the other one. – matt Dec 31 '21 at 17:12

4 Answers4

0

have you tried to remove the background color of webView?

webView.backgroundColor = .clear
Jinal Gor
  • 116
  • 2
  • 4
0

have you tried

self.webView.scrollView.backgroundColor = .clear
0

Suggesting an alternative route that could achieve the effect you desire: maybe you could introduce an opaque or semi transparent view or subview that covers the webview until your content loads. Something like this:enter image description here

You could have a callback that removes said view once you know you have a validated response from your request perhaps?

jimBeaux27
  • 117
  • 7
0

//Xcode13

webView.isOpaque = false; 
webView.backgroundColor = UIColor.clear;
gajuu
  • 1
  • 3