美文网首页
代码淘沙0622(B-html中图片缩放)

代码淘沙0622(B-html中图片缩放)

作者: 大风起兮_Seven | 来源:发表于2017-06-22 10:21 被阅读5次

    常用处理html中图片自适应屏幕宽度

    - (void)webViewDidFinishLoad:(UIWebView *)webView {
        NSString *jsStr = [NSString stringWithFormat:@"var script = document.createElement('script');"
                           "script.type = 'text/javascript';"
                           "script.text = \"function ResizeImages() { "
                           "var myimg,oldwidth;"
                           "var maxwidth=%lf;" //缩放系数
                           "for(i=0;i <document.images.length;i++){"
                           "myimg = document.images[i];"
                           "if(myimg.width > maxwidth){"
                           "oldwidth = myimg.width;"
                           "myimg.width = maxwidth;"
                           "}"
                           "}"
                           "}\";"
                           "document.getElementsByTagName('head')[0].appendChild(script);",SCREEN_WIDTH-25];
        
        [webView stringByEvaluatingJavaScriptFromString:jsStr];
        
        [webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"];
    }
    

    相关文章

      网友评论

          本文标题:代码淘沙0622(B-html中图片缩放)

          本文链接:https://www.haomeiwen.com/subject/ykgxcxtx.html