swift - WKWebView

Summary

  • 在APP中嵌入一个网页,相当于一个内置的浏览器,固定访问我们的服务。

Demo

import UIKit
import WebKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        self.view.backgroundColor = UIColor.gray
        var webView: WKWebView?
        webView = WKWebView(frame:CGRect(x:0, y:0, width:UIScreen.main.bounds.size.width, height:UIScreen.main.bounds.size.height))
        let rul = URL.init(string:("https://www.duchaoqun.cn/"))
        let request = URLRequest(url:rul!)
        webView?.load(request)
        self.view.addSubview(webView!)
    }

}
posted @ 2020-05-21 09:20  duchaoqun  阅读(1108)  评论(0编辑  收藏  举报