美文网首页
iOS-加载本地HTML文件

iOS-加载本地HTML文件

作者: Freedom_fly | 来源:发表于2017-08-23 16:10 被阅读13次

开发过程中登录注册的服务协议一般需要本地加载:
方法如下:
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];

相关文章

网友评论

      本文标题:iOS-加载本地HTML文件

      本文链接:https://www.haomeiwen.com/subject/evzddxtx.html