You can use it if you wanna make it in two separate views and show the 2nd viewController after clicking on the button:
import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate {
var webview: WKWebView!
override func loadView() {
let webconfig = WKWebViewConfiguration()
webview = WKWebView(frame: .zero, configuration: webconfig)
webview.uiDelegate = self
view = webview
}
override func viewDidLoad() {
super.viewDidLoad()
let myurl = URL(string: "https://google.com/")
let myRequest = URLRequest(url: myurl!)
webview.load(myRequest)
}
but if you wanna it in the same view you can use the below by using button action:
import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate {
var webview: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
}
func loadMyView() {
let webconfig = WKWebViewConfiguration()
webview = WKWebView(frame: .zero, configuration: webconfig)
webview.uiDelegate = self
view = webview
}
func viewWeb() {
let myurl = URL(string: "https://google.com/")
let myRequest = URLRequest(url: myurl!)
webview.load(myRequest)
}
@IBAction func buttonWebViewed(_ sender: Any) {
loadMyView()
viewWeb()
}
}