iOS开发 将html 富文本文字 转换成oc 的富文本

- (NSMutableAttributedString *)mf_htmlAttribute:(NSString *)htmlString{
    
    htmlString = [NSString stringWithFormat:@"<div>%@</div>",htmlString];
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding]
                                                                                          options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType }
                                                                               documentAttributes:nil
                                                                                            error:nil];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 3;
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attributedString.mutableString.length)];
    return attributedString;
}
posted @ 2022-01-27 14:13  Alerson  阅读(292)  评论(0编辑  收藏  举报