Simple Web View
Wade Cantley
I ran into a situation on the job where I needed to display some legal text. This isn't uncommon in a corporate environment but the text they wanted to use was just huge. It was really long and it needed to be in a place where other content was displayed.
After a few 30 minutes and figuring out that the legal text couldn't be paired down it dawned on me that we could link to the legal text AND put it in a place that could be easily changed as legal stuff tends to do. So this was the perfect opportunity to play with the WebView, something that I had not crossed paths with, and thankfully, it turns out it is pretty easy to implement.
Here are the steps
- Create a new project.
- Add a button to the Main view and add a seque.
- Add a new Web view with the web view and nav button to segue back.
- Add a web view controller
- Add some code.
Here is the video....
Here is the code in the web view controller
// // WebViewController.swift // WebViewTest // // Created by Chris Cantley on 6/25/15. // Copyright (c) 2015 Chris Cantley. All rights reserved. // import Foundation import UIKit class WebViewController: ViewController { @IBOutlet weak var webView: UIWebView! override func viewDidLoad() { //setup the URL let requestURL = NSURL(string: "http://www.google.com") //Setup the request with the URL inside it let request = NSURLRequest(URL: requestURL!) //Add the request into the web view webView.loadRequest(request) } }
And here is a link to the project.