[WEBVIEW] WkWebview With Float Button

Create a new project, In view controller where you want to show WKWebView embedded inside UIButton. and look like below.




Full Code Below.

import UIKit
import WebKit

class WebViewVC: UIViewController, WKNavigationDelegate {
    @IBOutlet weak var button: UIButton!
   
    lazy var webView: WKWebView = {
        let web = WKWebView()
        web.backgroundColor = UIColor.white
        web.isUserInteractionEnabled = true
        web.scrollView.showsHorizontalScrollIndicator = false
        web.scrollView.showsVerticalScrollIndicator = false
        web.translatesAutoresizingMaskIntoConstraints = false
        return web
    }()
   
    override func viewDidLoad() {
        super.viewDidLoad()
       
        button.layer.cornerRadius = button.frame.size.width / 2
        webView.navigationDelegate = self
        let url = URL(string: "https://www.google.com")
       
        let request = URLRequest(url: url!)
        webView.load(request)
        view.addSubview(webView)
        webView.addSubview(button)
       
        webView.topAnchor.constraint(equalTo: view.topAnchor, constant: 16).isActive = true
        webView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0).isActive = true
        webView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0).isActive = true
        webView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0).isActive = true
   
    }
   
   

}




No comments: