WKWebView

加载本地html

WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
WKWebView *wkWebView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:configuration];
wkWebView.backgroundColor = [UIColor whiteColor];
wkWebView.scrollView.showsVerticalScrollIndicator = NO;
[wkWebView.scrollView setContentInset:UIEdgeInsetsMake(0, 0, 44, 0)];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"abc" ofType:@"html"];
NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
NSError *error;
NSString *html = [NSString stringWithContentsOfFile:filePath
encoding:NSUTF8StringEncoding
error:&error];
[wkWebView loadHTMLString:html baseURL:baseURL];
[self.view addSubview:wkWebView];

加载一个网页

WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
WKWebView *wkWebView = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:configuration];
wkWebView.backgroundColor = [UIColor whiteColor];
wkWebView.scrollView.showsVerticalScrollIndicator = NO;
NSURL *url = [[NSURL alloc]initWithString:@"http://www.baidu.com"];
[wkWebView loadRequest:[NSURLRequest requestWithURL:url]];
[self.view addSubview:wkWebView];

加载本地PDF

- (void)didLoadLocalPDF:(NSURL *)filePath
{
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
WKWebView *wkWebView = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:configuration];
wkWebView.backgroundColor = [UIColor whiteColor];
wkWebView.scrollView.showsVerticalScrollIndicator = NO;
[wkWebView loadData:[NSData dataWithContentsOfURL:filePath] MIMEType:@"application/pdf" characterEncodingName:@"UTF-8" baseURL:nil];
[self.view addSubview:wkWebView];
}

加载在线PDF

WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
WKWebView *wkWebView = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:configuration];
wkWebView.backgroundColor = [UIColor whiteColor];
wkWebView.scrollView.showsVerticalScrollIndicator = NO;
NSURL *url = [[NSURL alloc]initWithString:@"https://xxx.pdf"];
[wkWebView loadRequest:[NSURLRequest requestWithURL:url]];
[self.view addSubview:wkWebView];