iOS-加载本地HTML文件
2017-08-23 本文已影响13人
Freedom_fly
开发过程中登录注册的服务协议一般需要本地加载:
方法如下:
1、加载文件
_webView = [[UIWebView alloc] init];
[self.view addSubview:_webView];
_webView.scrollView.showsVerticalScrollIndicator = NO;
_webView.delegate = self;
NSString* path = [[NSBundle mainBundle] pathForResource:@"服务协议" ofType:@"html"];
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]] ;
[_webView loadRequest:request];
2、加载代码
NSString* path = [[NSBundle mainBundle] pathForResource:@"服务协议" ofType:@"html"];
NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
NSString *html = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[_webView loadHTMLString:html baseURL:baseURL];