Is there a clever way to figure out what size a UIWebview needs to be to hold all text
I get a page full of info from the server VIA JSON. There is a lot of info and different 开发者_Go百科parts to the info, images, text, graphs etc. So i display it inside a UIScrollView so the whole page can scroll. I get some HTMl which i want to display inside a UIWebView. I have the HTML before i create the UIWebView so i can change the height of the UIWebView to contain all the text without the UIWebView itself needing to scroll. But it can vary in length each time i get a new load of data back from the server so i cant hardcore the height it needs to be.
So my question is. Given you have an NSString holding the HTML. Is there a way to calculate how high the UIWebViews frame needs to be, to contain all the HTML without having to scroll.
Hope you understand my question it is kinda long :)
Thanks, -Code
If it's ok to resize the webview (and the parent scroll view's contentSize
property) after the HTML finishes loading, you can use JavaScript to query the rendered height of the HTML and use that. See iPad - find the true height of a UIWebView
Well that would depand on the size of the text in the UIWebView. One way I can think of is to try finding out how many characters (letters) you need to fill one line in your UIWebView. Then use that number to devide your total number of characters in the NSString containing the HTML and base on that number lets call it lanes you could increase the hight of your UIWebView
精彩评论