Contact Us

Use the form on the right to contact us.

You can edit the text in this area, and change where the contact form on the right submits to, by entering edit mode using the modes on the bottom right. 


Oak Ridge, TN, 37830
United States

Swift-Snips

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

  1. Create a new project.
  2. Add a button to the Main view and add a seque.
  3. Add a new Web view with the web view and nav button to segue back.
  4. Add a web view controller
  5. 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.