webview加載html字符串正確方式

廢話不多代碼呈上

NSString *content = [model.contentInfo 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:14px; color: #878787; background-color:#F9F9F9;}\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>",[NSString stringWithFormat:@"推薦理由:<br>%@",content]];
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章