iOS webview Picture Adaptive screen width

Source: Internet
Author: User

This knowledge point is the most recent attempt to write the background interface  in the mobile display when the need to use this knowledge point, in the Webviewdidfinishload method to execute a section of JS code to  get each picture  Determine if the width is greater than the current phone screen size, and then adjust to the screen width display, not the same as the original display

The code is as follows:
1- (void) Webviewdidfinishload: (UIWebView *) WebView {2 //2, all have effect3NSString *js=@"var script = document.createelement (' script ');"4     "script.type = ' text/javascript ';"5     "script.text = \ "Function resizeimages () {"6     "var myimg,oldwidth;"7     "var maxwidth =%f;"8     "For (I=0;i <document.images.length;i++) {"9     "myimg = document.images[i];"Ten     "if (Myimg.width > MaxWidth) {" One     "oldwidth = myimg.width;" A     "myimg.width =%f;" -     "}" -     "}" the     "}\";" -     "document.getelementsbytagname (' head ') [0].appendchild (script);"; -Js=[nsstring Stringwithformat:js,[uiscreen Mainscreen].bounds.size.width,[uiscreen mainScreen].bounds.size.width- the]; - [WebView Stringbyevaluatingjavascriptfromstring:js]; +[WebView stringbyevaluatingjavascriptfromstring:@"resizeimages ();"]; -  +}

Reference Links:

iOS webview Picture Adaptive screen width

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.