Create WebView for iphone – UIWebview in swfit iOS

With UIWebview in iOS, you can display html content in your application. It not only loads local html files but also takes external page by assigning the url to the UIWebView. Please follow the steps below to create WebView in your existing iOS app.

  1. Drag UIWebView Control into the view of Main.storyboard
  2. Make UIWebview full screen by right clicking on the UIWebview and drag to the parent view to set the following constraints
    1. Equal Heights
    2. Equal Widths
    3. Center X Alignment
    4. Center Y Alignment
  3. Click on Assistant Editor to show the ViewController code and Main.storyboard UI side by side so you can set reference by right dragging the UIWebview into the ViewController class then enter the name of reference of the UIWebview.
  4. At the projector navigator, select the ViewController.swift or double click ViewController.swift and add the following code
import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var webView: UIWebView!
    var url = ""

    override func viewDidLoad() {
        // Do any additional setup after loading the view, typically from a nib.

        let urlToLoad = NSURL(string:url)
        let request = NSURLRequest(URL:urlToLoad!)


    override func didReceiveMemoryWarning() {
        // Dispose of any resources that can be recreated.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s