计算webView的 高度 和自适应屏幕大小

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

 

    [webView stringByEvaluatingJavaScriptFromString:

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

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

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

     "var myimg,oldwidth;"

     "var maxwidth=305;" //缩放系数

     "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);"];

    

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

    

    CGRect frame = webView.frame;

    frame.size.height = 1;

    webView.frame = frame;

    CGSize fittingSize = [webView sizeThatFits:CGSizeZero];

    frame.size = fittingSize;

    webView.frame = frame; 

    [self updateScrollViews:frame];

}

 

posted on 2014-11-07 15:24  助金  阅读(763)  评论(0编辑  收藏  举报