在iOS中计算PDF内容高度

时间:2013-12-24 05:17:25

标签: ios iphone objective-c

我必须在UIWebView上呈现PDF文件,但我无法计算PDF的实际高度,因为我使用UITableView所以我需要设置单元格具有UIWebView的高度。

我可以使用以下代码计算HTML内容。

    CGRect frame = newsWebView.frame;
    frame.size.height = 1;
    frame.size.height = newsWebView.scrollView.contentSize.height;  // Get the corresponding height from the webView's embedded scrollView.
    webViewHeight =frame.size.height ;

有没有办法计算PDF内容?

2 个答案:

答案 0 :(得分:1)

你可以尝试这个set sizeToFit属性并再次在webViewDidFinishLoad中设置UIWebView的框架

- (void)webViewDidFinishLoad:(UIWebView *)webView{
       [detailsWebView sizeToFit];
       [detailsWebView setFrame:CGRectMake(detailsWebView.frame.origin.x, detailsWebView.frame.origin.y, 300.0, detailsWebView.frame.size.height)];

}

在这里,您可以根据此方法中的PDF内容调整webview高度,然后调整单元格

答案 1 :(得分:0)

//试试此代码

- (void)webViewDidFinishLoad:(UIWebView *)aWebView
{        
    CGFloat height = [[aWebView stringByEvaluatingJavaScriptFromString:@"document.height"] floatValue];
    CGFloat width = [[aWebView stringByEvaluatingJavaScriptFromString:@"document.width"] floatValue];
    CGRect frame = aWebView.frame;
    frame.size.height = height;
    frame.size.width = width;
    aWebView.frame = frame;
}