昨日 在做IM时候,web端向ios发送消息"
//将HTML字符串转化为NSAttributedString富文本字符串- (NSString*)attributedStringWithHTMLString:(NSString*)htmlString {
NSDictionary *options = @{ NSDocumentTypeDocumentAttribute :NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute :@(NSUTF8StringEncoding) };
NSData *data = [htmlString dataUsingEncoding:NSUTF8StringEncoding];
NSAttributedString *string = [[NSAttributedString alloc] initWithData:data options:options documentAttributes:nil error:nil];
returnstring.string;
}
本文介绍了一种将HTML字符串转换为NSAttributedString富文本的方法。通过设置文档类型和字符编码选项,利用NSData加载HTML字符串,并通过NSAttributedString初始化实现转换。
2223

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



