I need to add a UIWebView and some buttons and labels inside a UIScrollView . I saw a lot of questions about how to add a UIWebView inside a UIScrollView , but unfortunately they could not help me complete my task. So kindly do not mark this as a duplicate or something like that.
Theoretically, the problem can be solved using the following steps:
1) Make UIWebView sub-item of UIScrollView .
2) Call setScrollEnabled:NO for the UIWebView to disable its own scrolling.
3) Set the content size of both UIScrollView and UIWebView for the size of the HTML string loaded inside the UIWebView .
I am using iOS 6 and StoryBoards. I added UIWebView as a sub-item of UIScrollView .
Then in my webViewDidFinishLoad I used the following:
NSString *webHeight = [webView stringByEvaluatingJavaScriptFromString:@"document.height;"]; NSLog(@"WebView Height %@", webHeight);
This gives me the height of the webview.
In StackOverFlow, I came across the following.
CGRect frame = webView.frame; frame.size.height = 1; webView.frame = frame; CGSize fittingSize = [webView sizeThatFits:CGSizeZero]; frame.size = fittingSize; webView.frame = frame; NSLog(@"size: %f, %f", fittingSize.width, fittingSize.height);
Then I set the size of the UIScrollView to the size of the UIWebView :
mainScrollView.contentSize = webView.bounds.size;
I can scroll down, but there is a lower space at the bottom, and the UIWebView does not make its size according to the size of the loaded html content.

It seems that UIScrollView resized it to the size of the contents of the UIWebView , but the UIWebView does not display it all. How can I solve this problem?
Please do not advise me about the Apple documentation that says you should not use UIWebView inside a UIScrollView . I already know this, but I want to use it in accordance with the requirements of my project.