iOS 加载本地的html文件
方法1:
self.webView = [[UIWebView alloc]initWithFrame:self.view.bounds]; NSString *path = [[NSBundle mainBundle]pathForResource:@"index" ofType:@"html"]; NSString *html = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; [self.webView loadHTMLString:html baseURL:nil]; [self.view addSubview:self.webView];
方法2:
NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]; NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]; NSString *html = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; [webView loadHTMLString:html baseURL:baseURL];
- 上一篇 »webpack务虚扫盲
- 下一篇 »js在html中的加载执行顺序