iphone - 我们可以根据内容放大 WebView 的高度吗?

标签 iphone ios xcode webview

我们正在开发一个显示“提示”列表的应用程序,其中“提示”的描述采用 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/

相关文章:

iphone - UIPickerView 看起来像 UIDatePicker 但有几秒钟

iphone - nsdateformatter 不适用于日本日历

ios - 在ios中按顺序下载音频文件

ios - XCode 8.1 更改了 Storyboard View 中的常量

objective-c - 如何在命令行中使用 xcodebuild?

ios - 在 Swift 中使用 MKLocalSearch 将一个图钉附加到用户位置,而不是蓝点

iphone - 无限循环添加 subview

iphone - View 的底部在模拟器和设备上被切断(单 View 应用程序)

ios - Objective-C 单元测试中的 Swift 类 - 生成的不完整 "-Swift.h"

iphone - UIGraphicsBeginImageContext 导致内存(泄漏)溢出