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