第一种
//html5 图片设置为屏幕宽
NSString *myStr = [NSString stringWithFormat:@"
",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:@" \n"
"
\n""
"body {margin:18;font-size:45;color:0x666666}\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"
"}"
"%@"
""
"",_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;
//
//后面的代码
。。。。。。
}