I am trying to make a tumblr app. When I make a get request for any post, they come back with html for the body. Currently I am take the html and shove it into a uiwebview. I set the width of the view because it is always the same but I cant figure out how to calculate the height of it. I am trying to place this into a uitable, so i need to figure out the height for each cell.
So basically is it possible to get the height of the uiwebview after it has render the html?
I use a javascript trick to do this.
Before loading the HTML String into the UIWebView, you need to add the following javascript into the HTML String.
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
The javascript will navigate UIWebView to a url scheme ready://
The value of document.body.offsetHeight is stored as the “host”
You have to intercept this request using the UIWebView delegate so that UIWebView does not navigate to ready://
“ready” scheme is just an arbitrary name. Basically the UIWebView is asked by the JavaScript to navigate to ready://234
“ready” is the custom URL scheme
“234” is an example of the UIWebView required height to render the content of HTML without scrolling.