美文网首页
iOS webview 加载html字符串,设置字体和图片自适应

iOS webview 加载html字符串,设置字体和图片自适应

作者: xu1Peng | 来源:发表于2021-03-29 10:16 被阅读0次

NSString *content = [content stringByReplacingOccurrencesOfString:@"&quot" withString:@"'"];

    content = [content stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];

    content = [content stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];

    content = [content stringByReplacingOccurrencesOfString:@"&quot;" withString:@"\""];

    NSString *htmls = [NSString stringWithFormat:@"<html> \n"

                      "<head> \n"

                      "<meta name=\"viewport\" content=\"initial-scale=1.0, maximum-scale=1.0, user-scalable=no\" /> \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>",content];

    [_webView loadHTMLString:htmls baseURL:nil];

相关文章

网友评论

      本文标题:iOS webview 加载html字符串,设置字体和图片自适应

      本文链接:https://www.haomeiwen.com/subject/xogvhltx.html