iOS与HTML交互问题

一.

加载后台传过来的HTML标签,文字都能正常显示但是图片显示不了。找问题找了很久没有发现那个地方写错,也问了别人都不知道,后来问了Android才知道,后台传过来的HTML标签,有些是转义过的。移动端这边识别不了。才造成了图片不显示。使用NSString替换字符串的方法把转衣服替换了。就OK。

        NSString * htmlString = [self.htmlString stringByReplacingOccurrencesOfString:@"\"" withString:@"""];

 

二.

图片文字正常显示以后,图片的样式和和大小显示的又不正确,问了下知道是后台传过来的只是body,需要自己拼接头部。问了公司的H5.

 

NSString *header =@"<head><meta name="viewport" content="initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no"><style>img{max- 100%; auto; height:auto;}</style><style>*{max-100%;max-height:100%}</style></head>";

        

        self.htmlString = [NSString stringWithFormat:@"<html>%@<body><p style="word-break:break-all">%@</p></body></html>",header,self.model.content];

 

PS:如果用到其他标签请看这篇文章http://blog.csdn.net/huang100qi/article/details/42596799

原文地址:https://www.cnblogs.com/huanghaipo/p/6904581.html