ios uiwebview 富文本图片自适应

- (void)webViewDidFinishLoad:(UIWebView *)webView {

    NSString *js=@"var script = document.createElement('script');"

    "script.type = 'text/javascript';"

    "script.text = \"function ResizeImages() { "

    "var myimg,oldwidth;"

    "var maxwidth = %f;"

    "for(i=0;i

        "myimg = document.images[i];"

        "if(myimg.width > maxwidth){"

            "oldwidth = myimg.width;"

            "myimg.width = %f;"

            "myimg.height = myimg.height*myimg.width/oldwidth"

        "}"

    "}"

    "}\";"

    "document.getElementsByTagName('head')[0].appendChild(script);";

    js=[NSString stringWithFormat:js,[UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.width-15];

    [webView stringByEvaluatingJavaScriptFromString:js];

    [webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"];

}

scalesPageToFit 属性不设置

 

 

你可能感兴趣的:(故障解决,ios,iphone)