【问题标题】:Set div height relative to UIWebView frame.size设置相对于 UIWebView frame.size 的 div 高度
【发布时间】:2012-06-18 16:01:19
【问题描述】:

我想让我的 div 的高度是

我在子类 UITableViewCell 中有一个 UIWebView。在那个 UIWebView 里面,我有一些带有一个 div 的基本 html。

_editorHTML = [@"<html>"
               "<head>"
               "<style>"
               ".contentContainer { font-family:Arial, Helvetica, sans-serif; font-size:1em; }"
               "</style>"
               "</head>"
               "<body>"
               "<div id=\"content\" contenteditable=\"true\" style=\"height:100%;\" class=\"contentContainer\">%@</div>"
               "</body>"
               "</html>" retain];

[_webView loadHTMLString:[NSString stringWithFormat:_editorHTML, @""] baseURL:[NSURL fileURLWithPath:directory]];

有没有办法让 div 的高度成为 UIWebView 的高度?当我设置 height:100% 时,它只会使 div 大约为 UIWebView 高度的四分之一。

【问题讨论】:

    标签: objective-c ios ios5 uiwebview


    【解决方案1】:

    [webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] 将为您提供内容的高度(在 html 完成加载后执行,例如在webViewDidFinishLoad 中)。此外,由于您是在 tableview 中执行此操作,因此您将处理单元格大小已更改的事实。

    请注意,如果您的 webview 已经高于内部内容的高度,它实际上会返回您的 web view 的高度。

    【讨论】:

      猜你喜欢
      • 2012-02-10
      • 2022-11-30
      • 1970-01-01
      • 2021-08-10
      • 2015-10-30
      • 2018-06-01
      • 2011-08-17
      • 2016-07-28
      • 2023-03-26
      相关资源
      最近更新 更多