UIWebView ContentSize高度

时间:2014-04-01 10:53:36

标签: ios webview uiscrollview height

我在UIImage内有UILabelUIWebViewUIScrollView。基本上,我正在计算UIImageUILabel的高度,并将其添加到UIWebView高度以设置UIScrollView的contentSize。

以下是我计算UIWebView高度的方法:

- (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];
}

问题是在某些情况下,UIWebView在底部被切断......任何想法为什么?

这可能是相关的:UIWebView内容是我无法控制的HTML代码。

1 个答案:

答案 0 :(得分:4)

尝试以下代码:

- (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);
}