在webview的代理写上重新调用web的js来适配
- (void)webViewDidFinishLoad:(UIWebView *)webview {
NSString *js = @"function imgAutoFit() { \
var imgs = document.getElementsByTagName('img'); \
for (var i = 0; i < imgs.length; ++i) {\
var img = imgs[i]; \
img.style.maxWidth = %f; \
} \
}";
js = [NSString stringWithFormat:js, [UIScreen mainScreen].bounds.size.width - 20];
[webview stringByEvaluatingJavaScriptFromString:js];
[webview stringByEvaluatingJavaScriptFromString:@"imgAutoFit()"];
}
网友评论