图片自适应宽度(webView加载的时候)
NSString *htmls = [NSString stringWithFormat:@"<html> \n"
"<head> \n"
"<style type=\"text/css\"> \n"
"body {font-size:15px;}\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"
"var httpP = \"\"+$img[p].getAttribute(\"src\");"
"$img[p].setAttribute(\"src\",httpP);"
"$img[p].style.width = '100%%';\n"
"$img[p].style.height ='auto'\n"
"}\n"
"}"
"</script>%@"
"</body>"
"</html>",model.content];
设置字体加载图片(label或者textView加载的时候)
NSString *htmls = [NSString stringWithFormat:@"<head><style>img{width:%f !important;height:auto} body{font-size:14px;font-family:Helvetica-Light;line-height:160%%;}</style></head>%@",JZYI_SCREEN_WIDTH - 2 * DISTANCE_15, self.content];
网友评论