美文网首页
WKWebView---load

WKWebView---load

作者: 初灬终 | 来源:发表于2018-12-06 20:56 被阅读4次

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]];

相关文章

  • WKWebView---load

    1.加载一个能直接访问的网址 2.加载一个本地HTML 方式一: 方式二:

网友评论

      本文标题:WKWebView---load

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