美文网首页
WKWebView自适应大小

WKWebView自适应大小

作者: FANTASIED | 来源:发表于2017-07-01 16:23 被阅读35次
NSString *jScript = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);";
    
WKUserContentController *wkUController = [[WKUserContentController alloc] init];
WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
[wkUController addUserScript:wkUScript];
    
WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];
wkWebConfig.userContentController = wkUController;
    
    
self.webView = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:wkWebConfig];
[self.view addSubview:self.webView];
    
    
NSString *pathStr = [[NSBundle mainBundle] pathForResource:@"storage" ofType:@"html"];
NSURL *fileURL = [NSURL fileURLWithPath:pathStr];
[self.webView loadFileURL:fileURL allowingReadAccessToURL:fileURL];

相关文章

网友评论

      本文标题:WKWebView自适应大小

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