iOS: 计算 UIWebView 的内容高度

- (void)webViewDidFinishLoad:(UIWebView *)wb
{
//方法1
CGFloat documentWidth = [[wb stringByEvaluatingJavaScriptFromString:@"document.getElementById('content').offsetWidth"] floatValue];
CGFloat documentHeight = [[wb stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"content\").offsetHeight;"] floatValue];
NSLog(@"documentSize = {%f, %f}", documentWidth, documentHeight); //方法2
CGRect frame = wb.frame;
frame.size.width = ;
frame.size.height = ; // wb.scrollView.scrollEnabled = NO;
wb.frame = frame; frame.size.height = wb.scrollView.contentSize.height; NSLog(@"frame = %@", [NSValue valueWithCGRect:frame]);
wb.frame = frame;
}

转:http://www.cnblogs.com/ihojin/p/webview-contentheight.html

iOS: 计算 UIWebView 的内容高度

上一篇:js导出带格式的表格(包括单元格合并,字体样式等)


下一篇:com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server