iOS webView 加载HTML5获取加载后的高度
来源:互联网 发布:js延迟加载方式 编辑:程序博客网 时间:2024/05/29 07:51
第一种
//html5 图片设置为屏幕宽 NSString *myStr = [NSString stringWithFormat:@"<head><style>img{max-width:%f !important;}</style></head>",screenWidth]; NSString *str = [NSString stringWithFormat:@"%@%@",myStr,html5文本];//////////////////////////////////////////////- (void)webViewDidFinishLoad:(UIWebView *)webView{ //HTML5的高度 NSString *htmlHeight = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"]; //HTML5的宽度 NSString *htmlWidth = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollWidth"]; //宽高比 float i = [htmlWidth floatValue]/[htmlHeight floatValue]; //webview控件的最终高度 float height = screenWidth/i; //后面的代码 。。。。。。 }
第二种
NSString *htmls = [NSString stringWithFormat:@"<html> \n" "<head> \n" "<style type=\"text/css\"> \n" "body {margin:18;font-size:45;color:0x666666}\n" "</style> \n" "</head> \n" "<body>" "<script type='text/javascript'>" "window.onload = function(){\n" "var $img = document.getElementsByTagName('img');\n" "for(var p in $img){\n" " $img[p].style.width = '100%%';\n" "$img[p].style.height ='auto'\n" "}\n" "}" "</script>%@" "</body>" "</html>",_model.content]; [_webView loadHTMLString:htmls baseURL:nil];- (void)webViewDidFinishLoad:(UIWebView *)webView{ NSString *htmlHeight = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"]; NSString *htmlWidth = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollWidth"]; float i = [htmlWidth floatValue]/[htmlHeight floatValue]; float height = screenWidth/i; // //后面的代码 。。。。。。}
阅读全文
0 0
- iOS webView 加载HTML5获取加载后的高度
- iOS 获取 webView 加载完成后的高度
- 获取WebView加载网页后的cookies
- ios webView 加载本地html5
- iOS storyboard约束加载webView自适应高度
- iOS storyboard约束加载webView自适应高度
- ios 获取webview的高度
- 关于获取图片在网页加载后的高度
- webView加载html5
- iOS 获取WebView高度
- webview加载assets下的html5页面
- iOS获取webView的内容高度
- 【iOS】swift-获取webView的高度
- webView获取链接后的url和加载经过处理后的HTML
- WebView加载html后的JS交互
- android WebView加载html5介绍
- android WebView加载html5介绍
- android WebView加载html5介绍
- Hive HQL练习
- Java中的Error与Exception
- 欢迎使用CSDN-markdown编辑器
- MySQL多源复制
- Redirecting to /bin/systemctl restart sshd.service
- iOS webView 加载HTML5获取加载后的高度
- Spring Boot插件spring tool suite安装及使用
- GR(Graceful Restart,平滑重启)
- Titan Graph DataBase 研究 (一)----环境搭建
- Android圆角图片轻量级CircleImageView
- svn clean up
- java_se_String_01
- hadoop集群出现live nodes为1的解决方案
- JavaScript停止冒泡和阻止浏览器默认行为