WebView加载图片适配屏幕尺寸

在webView结束加载的代理方法中调用:

NSString *js=@"var script = document.createElement('script');"
                
                "script.type = 'text/javascript';"
                
                "script.text = \"function ResizeImages() { "
                
                "var myimg,oldwidth;"
                
                "var maxwidth = %f;"
                
                "for(i=1;i  maxwidth){"
                
                "oldwidth = myimg.width;"
                
                "myimg.width = %f;"
                
                "}"
                
                "}"
                
                "}\";"
                
                "document.getElementsByTagName('head')[0].appendChild(script);ResizeImages()";
                
 NSString *htmls = [NSString stringWithFormat:js, self.view.bounds.size.width];
 [self.webView loadHTMLString:htmls baseURL:nil];
                

你可能感兴趣的:(iOS,webView适配图片)