Search code examples
c#xamarin.iosuiwebview

Create WebView in Xamarin.iOS


How can I implement a UIwebView for IOS in VisualStudio using Xamarin.IOS and C#? I can create the webView in the Storyboard but how can I define the URL?

And how can I get the current Url?


Solution

  • Click on the webview after adding a webview in the storyboard, then the Properties will show at the right-bottom of VS like this:

    enter image description here

    Add the Name as the screenshot shows, press the Enter. Now you can load a URL for the WebView in your .cs file like this:

                NSUrl url = NSUrl.FromString("https://www.google.com");
                NSUrlRequest urlRequest = NSUrlRequest.FromUrl(url);
                webView.LoadRequest(urlRequest);
    

    To get the current url of the webview when it already has loaded a URL via the code:

                webView.Request.Url.AbsoluteString;