需求背景
产品需要展示html格式的富文本字符串,这个html是用户可编辑的,但不能有交互行为。从设计稿上看,这段富文本字符串需要展示在一个tableViewCell里,并且得让其自适应高度。
使用UILabel去实现需求
实际上,UILabel是支持attributeString的,而attributeString又可以通过html字符串生成,如下:
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]
initWithData:[htmlStr
dataUsingEncoding:NSUTF8StringEncoding]
options:@{
NSDocumentTypeDocumentAttribute :
NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute :
@(NSUTF8StringEncoding)
}
documentAttributes:nil
error:nil];
而

本文探讨在iOS应用中展示用户编辑的HTML富文本的难题,包括UILabel的限制与WKWebView的解决方案,涉及表格边框显示、渐变文字渲染及自适应高度实现。
最低0.47元/天 解锁文章
5281

被折叠的 条评论
为什么被折叠?



