本文共 1067 字,大约阅读时间需要 3 分钟。
NSDictionary *options = @{ NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType }; NSAttributedString *attributeString = [[NSAttributedString alloc] initWithData:[@"改革开放 40年" dataUsingEncoding:NSUnicodeStringEncoding] options:options documentAttributes:nil error:nil]; NSRange range = NSMakeRange(0, attributeString.string.length); NSMutableAttributedString *mutableAttributeString = [[NSMutableAttributedString alloc] initWithAttributedString:attributeString]; [attributeString enumerateAttributesInRange:range options:NSAttributedStringEnumerationReverse usingBlock:^(NSDictionary * _Nonnull attrs, NSRange range, BOOL * _Nonnull stop) { UIFont *oldFont = [attrs objectForKey:NSFontAttributeName]; NSMutableDictionary *newattrs = [attrs mutableCopy]; [newattrs setValue:[UIFont systemFontOfSize:oldFont.pointSize] forKey:NSFontAttributeName]; [mutableAttributeString setAttributes:newattrs range:range]; }];复制代码
转载地址:http://mtyyo.baihongyu.com/