1.加载一个能直接访问的网址
WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.biquge5200.cc/75_75584/"]]];
[self.view addSubview:webView];
2.加载一个本地HTML
<!DOCTYPE html>
<html>
<body>
<h1>helloworld</h1>
</body>
</html>
方式一:
WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:webView];
NSString *path = [[NSBundle mainBundle] pathForResource:@"WebView" ofType:@"html"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]];
[webView loadRequest:request];
方式二:
WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:webView];
NSString *path = [[NSBundle mainBundle] pathForResource:@"WebView" ofType:@"html"];
//API_AVAILABLE(macosx(10.11), ios(9.0))
[webView loadFileURL:[NSURL fileURLWithPath:path] allowingReadAccessToURL:[NSURL fileURLWithPath:path]];
网友评论