ios WebView打开本地html文件

iOS 码拜 8年前 (2016-03-27) 1223次浏览
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)

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明ios WebView打开本地html文件
喜欢 (0)
[1034331897@qq.com]
分享 (0)