WKUserContentController *userContentController = [[WKUserContentController alloc] init];
NSString * webWidth = @"";
if (@available(iOS 11, *)) {
webWidth = @"device-width";
}else{
webWidth = [NSString stringWithFormat:@"%f",[UIScreen mainScreen].scale * [[UIScreen mainScreen] bounds].size.width];
}
NSString *jSString = jSString = [NSString stringWithFormat:@"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=%@'); document.getElementsByTagName('head')[0].appendChild(meta);",webWidth];
WKUserScript *wkUserScript = [[WKUserScript alloc] initWithSource:jSString injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
[userContentController addUserScript:wkUserScript];
WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];
wkWebConfig.userContentController = userContentController;
网友评论