iPad - find the true height of a UIWebView

浪子不回头ぞ 提交于 2020-01-14 04:17:05

问题


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

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?


回答1:


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


来源:https://stackoverflow.com/questions/4134863/ipad-find-the-true-height-of-a-uiwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!