Load local html into UIWebView using swift

前端 未结 13 2093
耶瑟儿~
耶瑟儿~ 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:05

    For swift 3 Use this:

    do
        {
            let testHTML = Bundle.main.path(forResource: "about", ofType: "html")
            let contents =  try NSString(contentsOfFile: testHTML!, encoding: String.Encoding.utf8.rawValue)
            let baseUrl = NSURL(fileURLWithPath: testHTML!) //for load css file
    
            mWebView.loadHTMLString(contents as String, baseURL: baseUrl as URL)
        }
        catch
        {
    
        }
    

提交回复
热议问题