IOS开发UIWebView获取页面动态高度
上一段代码大家体会一下。
UIWebView *webView =[[UIWebView alloc]initWithFrame:CGRectMake(0,kScreenWidth*300/375 +128,kScreenWidth,self.view.height-49-44)];
NSString *content =[item.note stringByReplacingOccurrencesOfString:@""" withString:@"'"];
content =[content stringByReplacingOccurrencesOfString:@"<" withString:@"<"];
content =[content stringByReplacingOccurrencesOfString:@">" withString:@">"];
content =[content stringByReplacingOccurrencesOfString:@""" withString:@"\""];
NSString *htmls =[NSString stringWithFormat:@" \n"
" \n"
" \n"
" \n"
"body {font-size:15px;}\n"
" \n"
" \n"
""
""
"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"
"}"
"%@"
""
"",content];
[webView loadHTMLString:htmls baseURL:nil];
webViewHeight =[[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"]floatValue]/2+40;