【发布时间】:2013-03-23 02:32:48
【问题描述】:
我在下面有这段代码来设置我的 UIWebView:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementById(\"image\").src=\"q%@.png\";", self.imageIndex]];
NSLog(@"%f", [[webView stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"image\").height;"] floatValue]);
CGFloat width = [[webView stringByEvaluatingJavaScriptFromString:@"document.width"] floatValue];
CGFloat height = [[webView stringByEvaluatingJavaScriptFromString:@"document.height"] floatValue];
CGSize contentSize = CGSizeMake(width, height);
[self setUpNewSize:contentSize];
}
我为具有 id 的对象设置了新图像(并且它有效)。但大小不变。如您所见,我使用 NSLog 打印高度值,但高度显示为 0.0000。
这是我的 HTML 文件:
<!DOCTYPE html>
<html>
<head>
<title>Question 1</title>
</head>
<body>
<h3 id="header">Question 1</h3>
<img id="image" src="" alt="" width="100%">
</body>
</html>
我对每张图片都有不同的高度,并且它会动态变化。所以我的问题是为什么当我调用 stringByEvaluatingJavaScriptFromString 时 document 和 img 的高度没有改变。也许我需要创建一些重新加载方法?
【问题讨论】:
标签: ios uiwebview stringbyevaluatingjavascr