Load local html into UIWebView using swift

前端 未结 13 2072
耶瑟儿~
耶瑟儿~ 2020-11-28 22:27

This one is driving me crazy early this morning. I want to load some local html into a web view:

class PrivacyController: UIViewController {

    @IBOutlet w         


        
13条回答
  •  孤独总比滥情好
    2020-11-28 23:23

    You can load html string or local html file in UIWebView.

    HTML string:

    func loadHtmlCode() {
        let htmlCode = "Wonderful web 

    wonderful web. loading html code in UIWebView" webView.loadHTMLString(htmlCode, baseURL: nil) }

    HTML file:

    func loadHtmlFile() {
        let url = NSBundle.mainBundle().URLForResource("contactus", withExtension:"html")
        let request = NSURLRequest(URL: url!)
        webView.loadRequest(request)
    }
    

    Details can be found here: http://webindream.com/load-html-uiwebview-using-swift/

提交回复
热议问题