iOS 修改 html富文本的字体font

核心代码
[attributedString addAttributes:@{NSFontAttributeName:appFont(14 * rectScale(), NO),NSParagraphStyleAttributeName:style} range:NSMakeRange(0, attributedString.length)];

    NSString *content = shareInfo[@"content"] ?: @"";
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithData:[content dataUsingEncoding:NSUnicodeStringEncoding] options:@{
    
     NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType } documentAttributes:nil error:nil];
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    style.minimumLineHeight = 25 * rectScale();
    style.maximumLineHeight = 25 * rectScale();
    [attributedString addAttributes:@{
    
    NSFontAttributeName:appFont(14 * rectScale(), NO),NSParagraphStyleAttributeName:style} range:NSMakeRange(0, attributedString.length)];

注意,这种写法会将html的富文本样式只改成一种字体
,如果原来的字体有多种,修改过之后之后一种font

修改前
请添加图片描述
修改后
请添加图片描述

猜你喜欢

转载自blog.csdn.net/LIUXIAOXIAOBO/article/details/121141946