skip to Main Content

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

4

Answers


  1. Chosen as BEST ANSWER

    //Xcode13

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

  2. have you tried to remove the background color of webView?

    webView.backgroundColor = .clear
    
    Login or Signup to reply.
  3. have you tried

    self.webView.scrollView.backgroundColor = .clear
    
    Login or Signup to reply.
  4. 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?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search