ios WebView打开本地html文件
解决方案
20
两种方式:
let webView = UIWebView(frame: CGRect(x: 0, y: 0, width: self.view.bounds.size.width, height: self.view.bounds.size.height)) self.view.addSubview(webView) webView.autoresizingMask = .FlexibleHeight | .FlexibleWidth let htmlFilePath = NSBundle.mainBundle().pathForResource("FileName", ofType: "html")! // 1. webView.loadData(NSData(contentsOfFile: htmlFilePath), MIMEType: "text/html", textEncodingName: "UTF-8", baseURL: nil) // 2. webView.loadHTMLString(NSString(contentsOfFile: htmlFilePath, encoding: NSUTF8StringEncoding, error: nil), baseURL: nil)