1, the picture is too big
-(void) Webviewdidfinishload: (UIWebView *) WebView { NSString *js = @ "function Imgautofit () { var IMGs = document. getElementsByTagName (' img '); for (var i = 0; i < imgs.length; ++i) { var img = imgs[i]; Img.style.maxWidth =%f; } } "; JS = [NSString stringwithformat:js, [UIScreen mainscreen].bounds.size.width-20]; [WebView Stringbyevaluatingjavascriptfromstring:js]; [WebView stringbyevaluatingjavascriptfromstring:@ "Imgautofit ()"];}
2. Content Height
To get the height by JS:document.body.offsetHeight;
#pragma mark-uiwebviewdelegate-(void) Webviewdidfinishload: (UIWebView *) WebView { cgfloat height = [[WebView] stringbyevaluatingjavascriptfromstring:@ "Document.body.offsetHeight;"] Intvalue]; if (self.webviewheight! = height && self.count <= 3) { self.webviewheight = height; self.count++; [Self UpdateUI];} } -(BOOL) WebView: (UIWebView *) WebView shouldstartloadwithrequest: (nsurlrequest *) Request Navigationtype: ( Uiwebviewnavigationtype) Navigationtype { self.webviewheight = webView.scrollView.contentSize.height; return YES;}
IOS Hybrid development--webview problem tips