1. 添加本地js文件, 并配置head中的属性
function increaseMaxZoomFactor() {
var element = document.createElement(‘meta‘);
element.name = "viewport";
element.content = "maximum-scale=5; width=980";
var head = document.getElementsByTagName(‘head‘)[0];
head.appendChild(element);
}
2. 添加webview代理方法
webView.scalesPageToFit = YES; // 自使用尺寸
webView.scrollView.bounces = NO; // 禁用滚动
3. 在webViewDidFinishLoad中调用本地js代码
NSString *path = [[NSBundle mainBundle]pathForResource:@"IncreaseZoomFactor" ofType:@"js"];
NSString *jsCode = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[webView stringByEvaluatingJavaScriptFromString:jsCode];
[webView stringByEvaluatingJavaScriptFromString:@"increaseMaxZoomFactor()"];
时间: 2024-10-13 10:07:02