iOS优秀开发文章

iOS WKWebView 加载本地html

2018-10-17  本文已影响6人  CaptainRoy
目录如图
屏幕快照 2018-10-17 下午5.19.45.png
导入 #import <WebKit/WebKit.h>
WKWebView *wkWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.view.bounds.size.width, self.view.bounds.size.height)];
[self.view addSubview:wkWebView];
    
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
NSString *basePath = [NSString stringWithFormat:@"%@",bundlePath];
NSURL *baseUrl = [NSURL fileURLWithPath:basePath isDirectory:YES];
NSString *indexPath = [NSString stringWithFormat:@"%@/driverCode.html",basePath];
NSString *indexContent = [NSString stringWithContentsOfFile:indexPath encoding:NSUTF8StringEncoding error:NULL];
[wkWebView loadHTMLString:indexContent baseURL:baseUrl];
上一篇 下一篇

猜你喜欢

热点阅读