使用WKWebView时,显示文字会偏小,是因为H5配置缺少了meta标签,可以让H5开发人员配置或在代码中加入以下内容; 需要禁用用户缩放手势时,可以再增加user-scalable=no字段,如下所示:
WKWebViewConfiguration *webConfiguration = [[WKWebViewConfiguration alloc] init];
NSString *js = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width, user-scalable=no'); document.getElementsByTagName('head')[0].appendChild(meta);";
WKUserScript *wkUserScript = [[WKUserScript alloc] initWithSource:js injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
WKUserContentController *wkUController = [[WKUserContentController alloc] init];
[wkUController addUserScript:wkUserScript];
webConfiguration.userContentController = wkUController;
网友评论