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.
- Drag UIWebView Control into the view of Main.storyboard
- Make UIWebview full screen by right clicking on the UIWebview and drag to the parent view to set the following constraints
- Equal Heights
- Equal Widths
- Center X Alignment
- Center Y Alignment
- 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.
- 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 = "http://www.google.com" override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let urlToLoad = NSURL(string:url) let request = NSURLRequest(URL:urlToLoad!) webView.loadRequest(request) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }