Reputation: 1113
I have a UIImage
, a UILabel
and a UIWebView
inside a UIScrollView
. Basically, I'm calculating the height of both the UIImage
and the UILabel
and adding it to the UIWebView
height to set the UIScrollView's contentSize.
Here's how I calculate the UIWebView height:
- (void) webViewDidFinishLoad:(UIWebView *)webView {
CGRect frame = webView.frame;
CGSize fittingSize = [webView sizeThatFits:webView.scrollView.contentSize];
frame.size = fittingSize;
webView.frame = frame;
self.scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, frame.size.height + y + 10);
[webView setFrame:CGRectMake(x-8, y, webView.frame.size.width, frame.size.height)];
[webView setContentMode:UIViewContentModeScaleAspectFit];
}
The problem is for some cases the UIWebView
is cut on the bottom... Any ideia why?
This might be relevant: the UIWebView
content is HTML code I have no control on.
Upvotes: 1
Views: 5026
Reputation: 144
try out the following code:
- (void)webViewDidFinishLoad:(UIWebView *)aWebView {
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);
}
Upvotes: 4