iOS WKwebview 圖片適應螢幕,控制圖片寬度 . 富文字
XML程式碼拼接一段下面程式碼:
其中htmlString為你要拼接的html
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"
" $img[p].style.width = '100%%';\n"
"$img[p].style.height ='auto'\n"
"}\n"
"}"
"</script>%@"
"</body>"
"</html>,htmlString];
[self.webView loadHTMLString:htmls baseURL:nil];