码迷,mamicode.com
首页 > 移动开发 > 详细

iOS: 计算 UIWebView 的内容高度

时间:2014-09-12 08:50:53      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   java   2014   div   

- (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 = 768;
frame.size.height = 1;

// 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

bubuko.com,布布扣

iOS: 计算 UIWebView 的内容高度

标签:style   blog   http   color   io   os   java   2014   div   

原文地址:http://www.cnblogs.com/ygm900/p/3967637.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!