Swift WKWebView读取本地html

哈喽,大家好    最近闲着无聊,学下Swift   以后会把一些知识点记录在这,以备用

废话不多说,直接上代码

/** WKWebView  的简单使用,读取本地html文件 */
let webView = WKWebView(frame: CGRect(x: 0, y: -20, width: self.view.frame.size.width, height: self.view.frame.size.height+20))
// addSubview   大家都懂,我就不解释了
view.addSubview(webView)
// 禁止顶部下拉和底部上拉效果,适用在  不让webview 有多余的滚动   设置后,滚动范围跟网页内容的高度相同
webView.scrollView.bounces = false
/** 加载本地html文件 */
//从主Bundle获取 HTML 文件的 url
let bundleStr = Bundle.main.url(forResource: "test/index", withExtension: "html")
webView.loadFileURL(bundleStr!, allowingReadAccessTo: Bundle.main.bundleURL)

猜你喜欢

转载自www.cnblogs.com/QJJIOSfront-end/p/10893145.html