I’m trying to have a scene inside a UIScrollView with a number of layout elements, including one with an arbitrary amount of simple HTML content–usually about 4-30 lines.
If I just toss the content into a UIWebView, then it will scroll the webview content in a fixed-height box. That isn’t what I want; since the entire page scrolls, I want the page to grow in length to fit the HTML content (no matter how tall or short it is), so only the page scrolls, without the UIWebView scrolling as well.
I need solutions that will work on both iOS5 and iOS6.
There is no completely clean way to do this. The question is if you really have to use HTML.
If you do, you can do the following to calculate the height of your
UIWebView:Implement the
UIWebViewDelegateprotocol and execute some JavaScript code after the web view finishes loading:After that, you can resize your
UIWebView‘s frame and layout the other subviews in theUIScrollViewaccordingly.