Saturday 24 June 2017

Simple Web Browser

STEP - 1 : Main.Storyboard

A. Add a Textfield, Button, WebView to Main.Storyboard.

B. Add @IBOutlet to ViewController.swift  and Button action (@IBAction) ( Press 'Ctrl + Mouse Left Key' and drag to ViewController )

STEP - 2 : Add 'App Transport Security Setting' to info.plist file.

STEP - 3 : Inside 'App Transport Security Setting' -> Add 'Allow Arbitrary Load' and set value 'Yes'.

STEP - 4 : ViewController.swift

//
//  ViewController.swift
//  WebBrowser
//
//  Created by Admin on 03/04/1939 Saka.
//  Copyright © 1939 Saka Admin. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    
    @IBOutlet weak var addressBar: UITextField!
    
    @IBOutlet weak var myWebview: UIWebView!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

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


    @IBAction func surfBrowser(_ sender: Any) {
        
       // var urName : String
        
        let url = URL(string: "http://\(addressBar.text!)")
        myWebview.loadRequest(URLRequest(url: url!))
    }
}



No comments:

Post a Comment