UIWebView的高度问题
2014-04-15 09:31
211 查看
#pragma mark-- #pragma mark--方法1 - (void)webViewDidFinishLoad:(UIWebView *)webView { CGFloat webViewHeight = 0.0f; if (webView.subviews.count > 0) { UIView *scrollerView = [webView.subviews objectAtIndex:0];//为什么要取第一个? if (scrollerView.subviews.count > 0) { UIView *webDocView = scrollerView.subviews.lastObject; if ([webDocView isKindOfClass:[NSClassFromString(@"UIWebDocumentView") class]]) { webViewHeight = webDocView.frame.size.height;//获取文档的高度 webView.frame= webDocView.frame; //更新UIWebView 的高度 } } } } #pragma mark-- #pragma mark--方法2 - (void)webViewDidFinishLoad:(UIWebView *)webView { CGSize actualSize = [webView sizeThatFits:CGSizeZero]; CGRect newFrame = webView.frame; newFrame.size.height = actualSize.height; webView.frame = newFrame; } #pragma mark-- #pragma mark--方法3 - (void)webViewDidFinishLoad:(UIWebView *)webView { CGFloat webViewHeight=[webView.scrollView contentSize].height; CGRect newFrame = webView.frame; newFrame.size.height = webViewHeight; webView.frame = newFrame; }
方法4
- (void)webViewDidFinishLoad:(UIWebView *)webView { CGFloat height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue]; CGRect frame = webView.frame; webView.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, height); }
相关文章推荐
- android Fragment用法
- Android程序使用代码的安装和卸载
- iOS开源项目之日志框架CocoaLumberjack
- Xcode5.1离线下载安装及使用iOS5模拟器进行开发调试的方法
- Android gradle 0.9 ,编译.so 文件需要注意
- android 资源ID生成规则
- 各种类型的Writable(Text、ByteWritable、NullWritable、ObjectWritable、GenericWritable、ArrayWritable、MapWritable、SortedMapWritable)转
- GHUnit for iOS测试指南
- 【Android】VirtualBox + android x86 模拟各种分辨率
- Android 去掉标题栏
- 修改web office apps 默认在浏览器中打开
- 【Android Developers Training】 95. 创建一个同步适配器
- 如何整合Office Web Apps至自己开发的系统(二)
- 如何整合Office Web Apps至自己开发的系统(一)
- iOS开源项目之日志框架CocoaLumberjack
- android:layout_weight的一些疑惑的地方
- android选择图片或拍照图片上传到服务器(包括上传参数)
- block介绍(四)揭开神秘面纱(下)
- block介绍(三)揭开神秘面纱(上)
- ios视频播放