IOS: Calculating the content height of UIWebView

Source: Internet
Author: User

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

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.