美文网首页
ios wkWebView 加载本地html(有css和js等文

ios wkWebView 加载本地html(有css和js等文

作者: 读书人heart | 来源:发表于2019-07-22 19:49 被阅读0次

拉入html文件夹 选第一和第三

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

相关文章

网友评论

      本文标题:ios wkWebView 加载本地html(有css和js等文

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