First HTML file content
index.html
Loading HTML files
-(void) viewdidload{ [Super Viewdidload]; Additional setup after loading the view, typically from a nib. NSBundle *mainbundle = [NSBundle mainbundle]; Nsurl *indexfileurl = [mainbundle urlforresource:@ "index" withextension:@ "html"]; [Self.webview loadrequest:[nsurlrequest requestwithurl:indexfileurl];}
Calculate the actual height after WebView display content
Two methods, Method 1 can get the actual height of the content, method 2 Get the content display complete after the WebView size (including uiedgeinsets)
-(void) Webviewdidfinishload: (UIWebView *) wb{ //Method 1 cgfloat documentwidth = [WB stringbyevaluatingjavascriptfromstring:@ "document.getElementById (' content '). offsetwidth"] floatvalue]; CGFloat documentheight = [WB stringbyevaluatingjavascriptfromstring:@ "document.getElementById (\" content\ "). offsetheight; "] Floatvalue]; NSLog (@ "DocumentSize = {%f,%f}", Documentwidth, documentheight); Method 2 CGRect frame = wb.frame; Frame.size.width = 768; Frame.size.height = 1;// wb.scrollView.scrollEnabled = NO; Wb.frame = frame; Frame.size.height = wb.scrollView.contentSize.height; NSLog (@ "frame =%@", [Nsvalue valuewithcgrect:frame]); Wb.frame = frame;}
:
IOS: Calculating the content height of UIWebView