iOS-加载本地HTML文件

开发过程中登录注册的服务协议一般需要本地加载:
方法如下:
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];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容