webView适应图片

2017-06-07  本文已影响5人  BlueBar

在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()"];
    }
上一篇下一篇

猜你喜欢

热点阅读