I'm trying to use UIWebView inside UIScrollView, I want to display an webview under an image and make them scrollable. So I flowed those step :
- Desactivate the Scroll Property for UIWebView
- Set the UIScrollView and UIWebView height equals to content size.
And this my code :
- (void)viewDidLoad {
[super viewDidLoad];
self.contentReader.scrollView.scrollEnabled = NO;
NSString *myDescriptionHTML = [NSString stringWithFormat:@"<html> \n"
"<head> \n"
"<style type=\"text/css\"> \n"
"body {font-family: \"%@\"; font-size: %d;}\n"
"</style> \n"
"</head> \n"
"<body>%@</body> \n"
"</html>", @"JF Flat", 18, self.thePost.content];
[self.contentReader loadHTMLString:[NSString stringWithFormat:@"<div style='text-align:right; text-align:justify; direction:rtl'><style type='text/css'>img { max-width: 100%%; width: auto; height: auto; }</style><style type='text/css'>iframe { max-width: 100%%; width: auto; height: auto; }</style>%@<div>",myDescriptionHTML] baseURL:nil];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
// get the html content height
NSString *output = [webView stringByEvaluatingJavaScriptFromString:@"document.height;"];
NSLog(@"Content Size %@",output);
// adjust the height of webView
NSLog(@"WebView Hieght before Update%f", webView.frame.size.height);
CGRect frame = webView.frame;
frame.size.height = 1;
webView.frame = frame;
CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
frame.size = fittingSize;
webView.frame = frame;
NSLog(@"WebView Hieght After Update%f", webView.frame.size.height);
[self.scroller setContentSize:webView.bounds.size];
}
And This is the Log message :
[5150:203791] WebView Hieght before Update360.000000 [5150:203791] WebView Hieght After Update5888.000000
The Problem is that when I scroll down the content is not showed, nothing is showed. check the picture :
Update Debug View Hearachy.
As you can see the WebView height in the view hierarchy hasn't changed. Only the web page has changed the size.