iPad - 找到UIWebView的真正高度 [英] iPad - find the true height of a UIWebView
问题描述
我在一家媒体公司工作,在我们的iPad应用程序中,我们正在升级我们的内容,使其看起来更好。以前,我们使用UILabel来显示帖子的内容。我用它来获取我的UILabel的实际高度:
I work for a media company, and in our iPad application we're upgrading our content so it looks better. Previously, we used a UILabel to display the contents of our posts. I used this to get the actual height of my UILabel:
CGSize expectedSize = [label.text sizeWithFont:label.font
constrainedToSize:maximumLabelSize lineBreakMode:label.lineBreakMode];
但是,我们将帖子的内容更改为HTML,因此我使用的是UIWebView。有没有办法找到UIWebView的真实高度,就像我使用UILabel一样?
However, we changed our posts' content to HTML, so I'm using a UIWebView. Is there a way to find the true height of the UIWebView, like I do with the UILabel?
推荐答案
与普通字符串不同,您可能只能在Web视图完成渲染后才能获得高度。以下是如何在Web视图委托方法中执行此操作:
Unlike with a plain string, you'll probably only be able to get the height once the web view finishes rendering. Here's how you can do it in a web view delegate method:
- (void)webViewDidFinishLoad:(UIWebView *)webview
{
NSString *heightString = [webview stringByEvaluatingJavaScriptFromString:
@"document.body.clientHeight"];
int height = [heightString intValue];
...
}
这篇关于iPad - 找到UIWebView的真正高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!