Close Menu
  • Home
  • AI
  • Big Data
  • Cloud Computing
  • iOS Development
  • IoT
  • IT/ Cybersecurity
  • Tech
    • Nanotechnology
    • Green Technology
    • Apple
    • Software Development
    • Software Engineering

Subscribe to Updates

Get the latest technology news from Bigteetechhub about IT, Cybersecurity and Big Data.

    What's Hot

    Working with @Generable and @Guide in Foundation Models

    July 18, 2025

    Navigating the labyrinth of forks

    July 18, 2025

    OpenAI unveils ‘ChatGPT agent’ that gives ChatGPT its own computer to autonomously use your email and web apps, download and create files for you

    July 18, 2025
    Facebook X (Twitter) Instagram
    Facebook X (Twitter) Instagram
    Big Tee Tech Hub
    • Home
    • AI
    • Big Data
    • Cloud Computing
    • iOS Development
    • IoT
    • IT/ Cybersecurity
    • Tech
      • Nanotechnology
      • Green Technology
      • Apple
      • Software Development
      • Software Engineering
    Big Tee Tech Hub
    Home»iOS Development»Exploring WebView and WebPage in SwiftUI for iOS 26
    iOS Development

    Exploring WebView and WebPage in SwiftUI for iOS 26

    big tee tech hubBy big tee tech hubJune 21, 2025004 Mins Read
    Share Facebook Twitter Pinterest Copy Link LinkedIn Tumblr Email Telegram WhatsApp
    Follow Us
    Google News Flipboard
    Exploring WebView and WebPage in SwiftUI for iOS 26
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link


    In iOS 26, SwiftUI finally introduced one of its most highly anticipated components: WebView, a native solution for displaying web content. Before this update, SwiftUI developers had to rely on the UIKit framework, using UIViewRepresentable to wrap WKWebView or SFSafariViewController in order to embed a web view. With the arrival of WebView, Apple now provides a fully native SwiftUI approach to integrating web browsing capabilities into apps. In this tutorial, I’ll give you a quick overview of the new WebView and show you how to use it in your own app development.

    The Basic Usage of WebView

    To load a web page using the new WebView, you simply import the WebKit framework and instantiate the view with a URL. Here is an example:

    import SwiftUI
    import WebKit
    
    struct ContentView: View {
        var body: some View {
            WebView(url: URL(string: "
        }
    }
    

    With just a single line of code, you can now embed a full-featured mobile Safari experience directly in your app—powered by the same WebKit engine that runs Safari.

    swiftui-webview-basics.png

    An Alternative Way of Loading Web Content

    In addition to WebView, the WebKit framework also introduces a new class called WebPage. Rather than passing a URL directly to WebView, you can first create a WebPage instance with the URL and then use it to display the web content. Below is the sample code that achieves the same result:

    struct ContentView: View {
        @State private var page = WebPage()
        
        var body: some View {
            
            WebView(page)
                .ignoresSafeArea()
                .onAppear {
                    if let pageURL = URL(string: " {
                        let urlRequest = URLRequest(url: pageURL)
                        page.load(urlRequest)
                    }
                }
        }
    }
    

    Working with WebPage

    In most cases, if you simply need to display web content or embed a browser in your app, WebView is the most straightforward approach. If you need finer control over how web content behaves and interacts with your application, WebPage offers more detailed customization options like accessing web page properties and programmatic navigation.

    For example, you can access the title property of the WebPage object to retrieve the title of the web page:

    Text(page.title)
    Text(page.url)
    

    You can also use the url property to access the current URL of the web page.

    swiftui-webview-webpage-properties.png

    If you want to track the loading progress, the estimatedProgress property gives you an approximate percentage of the page’s loading completion.

    Text(page.estimatedProgress.formatted(.percent.precision(.fractionLength(0))))
    

    Other than accessing its properties, the WebPage class also lets you control the loading behavior of a web page. For example, you can call reload() to refresh the current page, or stopLoading() to halt the loading process.

    Loading Custom HTML Content Using WebPage

    Besides loading a URLRequest, the WebPage class’s load method can also handle custom HTML content directly. Below is the sample code for loading a YouTuber player:

    struct ContentView: View {
        
        @State private var page = WebPage()
        
        private let htmlContent: String = """
            

    """ var body: some View { WebView(page) .onAppear { page.load(html: htmlContent, baseURL: URL(string: "about:blank")!) } } }

    If you place the code in Xcode, the preview should show you the YouTube player.

    swiftui-webview-youtube.png

    Executing Javascript

    The WebPage object not only lets you load HTML content—it also allows you to execute JavaScript. You can use the callJavaScript method and pass in the script you want to run. Here is an example:

    struct ContentView: View {
        
        @State private var page = WebPage()
        
        private let snippet = """
            document.write("");
            """
        
        var body: some View {
            
            WebView(page)
                .task {
                    do {
                        try await page.callJavaScript(snippet)
                    } catch {
                        print("JavaScript execution failed: \(error)")
                    }
                }
        }
    }
    

    Summary

    The new native WebView component in SwiftUI makes it much easier to display web content within iOS apps, removing the need to rely on UIKit wrappers. SwiftUI developers can choose between two key approaches:

    • WebView: Ideal for straightforward use cases where you just need to load and display a web page.
    • WebPage: Offers more granular control, allowing you to access page properties, track loading progress, reload or stop loading, and even execute JavaScript.

    This native SwiftUI solution brings a cleaner, more streamlined experience to embedding web content in your apps.



    Source link

    Exploring iOS SwiftUI WebPage WebView
    Follow on Google News Follow on Flipboard
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Copy Link
    tonirufai
    big tee tech hub
    • Website

    Related Posts

    Working with @Generable and @Guide in Foundation Models

    July 18, 2025

    Exploring supersymmetry through twisted bilayer materials – Physics World

    July 18, 2025

    Deep dive into Swift frameworks

    July 17, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Editors Picks

    Working with @Generable and @Guide in Foundation Models

    July 18, 2025

    Navigating the labyrinth of forks

    July 18, 2025

    OpenAI unveils ‘ChatGPT agent’ that gives ChatGPT its own computer to autonomously use your email and web apps, download and create files for you

    July 18, 2025

    Big milestone for the future of quantum computing.

    July 18, 2025
    Advertisement
    About Us
    About Us

    Welcome To big tee tech hub. Big tee tech hub is a Professional seo tools Platform. Here we will provide you only interesting content, which you will like very much. We’re dedicated to providing you the best of seo tools, with a focus on dependability and tools. We’re working to turn our passion for seo tools into a booming online website. We hope you enjoy our seo tools as much as we enjoy offering them to you.

    Don't Miss!

    Working with @Generable and @Guide in Foundation Models

    July 18, 2025

    Navigating the labyrinth of forks

    July 18, 2025

    Subscribe to Updates

    Get the latest technology news from Bigteetechhub about IT, Cybersecurity and Big Data.

      • About Us
      • Contact Us
      • Disclaimer
      • Privacy Policy
      • Terms and Conditions
      © 2025 bigteetechhub.All Right Reserved

      Type above and press Enter to search. Press Esc to cancel.