【发布时间】:2014-04-03 05:22:02
【问题描述】:
我目前有一个 UIWebView 对象,它注入了以下 html 字符串:
<html>
<head>
<meta name="viewport" content="width=device-width" />
<style type="text/css">
body {
color: purple;
background-color: #d8da3d;
}
</style>
</head>
<body>
<div id="content" contenteditable="true"> </div>
<div style="font-family: Helvetica"> Sample text </div>
</body>
</html>
似乎用上面的html代码,有问题的WebView的contentSize高度是548px,而实际上,它应该比这要小得多,因为只有两行。我也确实加载了对 www.google.com 的 URL 请求。根据我设置的断点,contentSize 似乎确实增加了适当的数量。
所以我想知道是否可以根据 WebView 的内容(或者在我的情况下,使用上述 html 文本设置的 WebView)调整 contentSize 高度。我怀疑我可能必须指定某种 .css 参数,例如高度或最小高度(我已经尝试过这样做,但无济于事)。任何帮助将不胜感激!
编辑:不确定这是否有帮助,但这是我用来设置 html 内容的代码。我在项目中包含了 .html 文件,并在我的视图控制器中使用以下行设置了 WebView(使用情节提要创建)html 内容:
NSString *path = [[NSBundle mainBundle] pathForResource:@"compose" ofType:@"html"];
NSString *htmlString = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[self.webView loadHTMLString:htmlString baseURL:nil];
Edit2:经过一番修修补补,我想我知道发生了什么。似乎在 WebView 的内容高度
【问题讨论】: