Created
June 21, 2017 19:56
-
-
Save hskang9/fd62b5f841a277f8e8dd4fd1cdb3a5cb to your computer and use it in GitHub Desktop.
SimpleBrowserViewController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// WebViewController.swift | |
// SimpleBrowserViewController | |
// | |
// Created by hyungsukkang on 6/22/17. | |
// Copyright © 2017 Hyungsuk Kang. All rights reserved. | |
// | |
import UIKit | |
import Foundation | |
import WebKit | |
class WebViewController: UIViewController, UISearchBarDelegate, UIWebViewDelegate { | |
@IBOutlet weak var searchBar: UISearchBar! | |
@IBOutlet weak var webView: UIWebView! | |
@IBAction func backwardButton(_ sender: UIBarButtonItem) { | |
webView.goBack() | |
} | |
@IBAction func forwardButton(_ sender: UIBarButtonItem) { | |
webView.goForward() | |
} | |
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) { | |
searchBar.resignFirstResponder() | |
let text = searchBar.text | |
let myURL = URL(string: text!) | |
let myRequest = URLRequest(url: myURL!) | |
self.webView!.loadRequest(myRequest) | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.webView.delegate = self | |
self.searchBar.delegate = self | |
} | |
func webViewDidFinishLoad(_ webView: UIWebView) { | |
if let text = webView.request?.url?.absoluteString{ | |
searchBar.text = text | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment