您好,欢迎来到华佗小知识。
搜索
您的当前位置:首页WKWebView自适应大小

WKWebView自适应大小

来源:华佗小知识
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];

Copyright © 2019- huatuo0.cn 版权所有 湘ICP备2023017654号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务