WebView picture Adaptation screen when loading HTML

Source: Internet
Author: User

Today using WebView loading HTML, found that the picture is too large, no adaptation screen, so I set webview.scalespagetofit = YES, after the setting, the picture is really small, but the text is correspondingly reduced, and the picture is too small, nothing to match the screen, does not meet my requirements , so I thought of using JS to solve

1- (void) Webviewdidfinishload: (UIWebView *) Web2 {3     intCount = [[WebView stringbyevaluatingjavascriptfromstring:@"Document.images.length"] Intvalue];//get the number of IMG tags4      for(intI=0; i<count; i++) {5[WebView stringbyevaluatingjavascriptfromstring:[nsstring stringWithFormat:@"document.images[%d].style.maxwidth= ' 100%% '", I]];//picture width 100% fit, if greater than 320, zoom, if less than not processed6[WebView stringbyevaluatingjavascriptfromstring:[nsstring stringWithFormat:@"document.images[%d].style.height= ' auto '", I]];//Picture Height Adaptive7     }8}

WebView picture Adaptation screen when loading HTML

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.