iosswiftwebviewxcode13

Remove White Screen Before Loading WebView in Xcode13?


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)
        ])}
}

Solution

  • //Xcode13

    webView.isOpaque = false; 
    webView.backgroundColor = UIColor.clear;