我们正在开发一个显示“提示”列表的应用程序,其中“提示”的描述采用 HTML 格式,并且可能包含“”标签。
我们正在使用 WebView 显示描述,并希望根据“提示”描述的内容扩展 WebView 的高度(scale up the height)。
如果有任何可能,请告诉我们。
非常感谢。
最佳答案
在 webViewDidFinishLoad 委托(delegate)方法中,从 html 正文中获取高度。
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
float newHeight= [[self.webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"] floatValue];
或
如果你想用id( example:<div id='tips' style='background: red'>This is just an example test.</div
检索特定div标签的高度>
//然后,这样做
NSString *output = [webview stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"tips\").offsetHeight;"];
//转为 float
//然后像这样设置新的高度。
[webview setBounds:CGRectMake(oldBounds.x, oldBounds.y, oldBounds.width, newHeight)];
快乐编码:)
关于iphone - 我们可以根据内容放大 WebView 的高度吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14907958/