How can I load a local HTML file into the UIWebView?

前端 未结 7 985
有刺的猬
有刺的猬 2020-12-09 03:17

How can we load our own html file into the UIWebView?

7条回答
  •  忘掉有多难
    2020-12-09 03:35

    Swift Version 2.1

    // load html to String with Encoding
    let path = NSBundle.mainBundle().pathForResource("policy", ofType: "html")
    do {
        let fileHtml = try NSString(contentsOfFile: path!, encoding: NSUTF8StringEncoding)
        webView.loadHTMLString(fileHtml as String, baseURL: nil)
    }
    catch {
    
    }
    

提交回复
热议问题