Ali RJ
Ali RJ

Reputation: 159

how to add navigation controller to WebView?

I have used the following code to create a webView app in swift. but I need to also add a navigation bar at the bottom that goes to different pages of the website. And those are just another link but the webView is taking the whole screen and I can't seem to add the Nav bar to it. Help is appreciated in advance.

import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate {

    @IBAction func goBack(_ sender: Any) {
        self.webView.goBack()
    }
    var webView: WKWebView!

    override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self
        view = webView
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        let myURL = URL(string:"https://test.com")
        let myRequest = URLRequest(url: myURL!)
        webView.load(myRequest)
    }}

Upvotes: 0

Views: 642

Answers (1)

Hitesh Borse
Hitesh Borse

Reputation: 479

In Xib or storyboard add a subview to the bottom And change web view bottom constraint constant value.

WebView constraint enter image description here

SubView constraint enter image description here

Upvotes: 1

Related Questions