iOS 修改 html富文本的字体font
核心代码[attributedString addAttributes:@{NSFontAttributeName:appFont(14 * rectScale(), NO),NSParagraphStyleAttributeName:style} range:NSMakeRange(0, attributedString.length)];NSString *content = shareInf
·
核心代码
[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
修改前
修改后
更多推荐
已为社区贡献11条内容
所有评论(0)