iOS: Make WebView fullscreen (hide white background behind home button)

3k Views Asked by At

New to iOS development.

ContentView.swift:

struct ContentView: View {
    var body: some View {
         WebView(url: "https://www.stackoverflow.com")
    }
}

WebView.swift:

struct WebView: UIViewRepresentable {
    
    var url: String
    
    func makeUIView(context: Context) -> WKWebView {
        guard let url = URL(string: self.url) else {
            return WKWebView();
        }
              
        let request = URLRequest(url: url)
        let wkWebView = WKWebView()
        wkWebView.load(request)
        wkWebView.allowsBackForwardNavigationGestures = true
        return wkWebView
    }
    
    func updateUIView(_ uiView: WKWebView, context: UIViewRepresentableContext<WebView>) {
      
    }
}

results in a white bar behind the home button indicator:

white bar

How can I make the webview fullscreen so that there is no more white bar behind the home button?

1

There are 1 best solutions below

4
Kstin On BEST ANSWER

You need to set bottom space of Your WebView not to Safe Area but to Superview Select View here

storyboard example

for SwiftUI version just do

struct ContentView: View {
    var body: some View {
         WebView(url: "https://www.stackoverflow.com")
         .edgesIgnoringSafeArea([.bottom])
    }
}