Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I use a javascript trick to do this.</p> <p>Before loading the HTML String into the UIWebView, you need to add the following javascript into the HTML String.</p> <pre><code>NSMutableString *javaScript = [[NSMutableString alloc] init]; [javaScript appendString:@"&lt;script type=\"text/javascript\"&gt;"]; [javaScript appendString:@" window.onload = function() {"]; [javaScript appendString:@" window.location.href = \"ready://\" + document.body.offsetHeight;"]; [javaScript appendString:@" }"]; [javaScript appendString:@"&lt;/script&gt;"]; </code></pre> <p>This javascript will be triggered when the UIWebView has finished rendering and knew the required UIWebView height to show the entire content without scrolling up and down. The height is given by javascript variable document.body.offsetHeight</p> <p>The javascript will navigate UIWebView to a url scheme ready://</p> <p>The value of document.body.offsetHeight is stored as the "host"</p> <p>You have to intercept this request using the UIWebView delegate so that UIWebView does not navigate to ready://</p> <pre><code>- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { NSURL *url = [request URL]; if (navigationType == UIWebViewNavigationTypeOther) { if ([[url scheme] isEqualToString:@"ready"]) { float contentHeight = [[url host] floatValue]; NSLog(@"web height:%f",contentHeight); //You can use the contentHeight to resize the UIWebView frame return NO; //Prevent the UIWebView to navigate to this ready:// scheme } } return YES; } </code></pre> <p>"ready" scheme is just an arbitrary name. Basically the UIWebView is asked by the JavaScript to navigate to ready://234</p> <p>"ready" is the custom URL scheme</p> <p>"234" is an example of the UIWebView required height to render the content of HTML without scrolling. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload