All I need is to loop through all attributes of NSAttributedString
and increase their font size. So far I got to the point where I successfully loop through and manipulate attributes but I cannot save back to NSAttributedString
. The line I commented out is not working for me. How to save back?
NSAttributedString *attrString = self.richTextEditor.attributedText;
[attrString enumerateAttributesInRange: NSMakeRange(0, attrString.string.length)
options:NSAttributedStringEnumerationReverse usingBlock:
^(NSDictionary *attributes, NSRange range, BOOL *stop) {
NSMutableDictionary *mutableAttributes = [NSMutableDictionary dictionaryWithDictionary:attributes];
UIFont *font = [mutableAttributes objectForKey:NSFontAttributeName];
UIFont *newFont = [UIFont fontWithName:font.fontName size:font.pointSize*2];
[mutableAttributes setObject:newFont forKey:NSFontAttributeName];
//Error: [self.richTextEditor.attributedText setAttributes:mutableAttributes range:range];
//no interfacce for setAttributes:range:
}];
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…