ios wkWebViewローカルhtml(cssやjsなどのフォルダがある)
915 ワード
htmlフォルダに引き込む第1と第3を選択
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
[configuration setValue:@YES forKey:@"_allowUniversalAccessFromFileURLs"];
//
CGFloat width = self.view.frame.size.width;
CGFloat height = self.view.frame.size.height -20;
webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 20, width, height) configuration:configuration];
[self setAutomaticallyAdjustsScrollViewInsets:NO];
webView.navigationDelegate = self;
[self.view addSubview: webView];
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"index" ofType:@"html"];
// NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
NSURL *url = [NSURL fileURLWithPath:filePath];
[webView loadRequest:[NSURLRequest requestWithURL:url]];