Book Image

iOS Development with Xamarin Cookbook

By : Dimitrios Tavlikos (USD)
Book Image

iOS Development with Xamarin Cookbook

By: Dimitrios Tavlikos (USD)

Overview of this book

Table of Contents (22 chapters)
iOS Development with Xamarin Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a simple web browser


In this recipe, we will discuss displaying online content with the UIWebView class.

Getting ready

Create a new Single View Application project in Xamarin Studio and name it WebBrowserApp.

How to do it...

Perform the following steps:

  1. Open the WebBrowserAppViewController.xib file in Interface Builder and add a UIWebView object on the main view. Create and connect an outlet for it with the name webView. Save the document.

  2. Override the ViewDidAppear method in the WebBrowserAppViewController class, as shown in the following code:

    public override void ViewDidAppear (bool animated)
    {
      NSUrl url = new NSUrl ("http://software.tavlikos.com");
      NSUrlRequest urlRequest = new NSUrlRequest (url);
      this.webView.LoadRequest (urlRequest);
    }
  3. Compile and run the app on the simulator. Watch the website load on the screen!

How it works...

The UIWebView class is iOS SDK's web browser control. To load web content, we just have to call its LoadRequest method, which accepts a parameter of...