objective c - UITextView and NSMutableAttributedText -


uitextview shows formatted text when use nsattributedstring:

nsattributedstring* s1 = [[nsattributedstring alloc] initwithstring:@"hello there!"                                 attributes:@{nsforegroundcolorattributename:[uicolor redcolor], nsfontattributename: [uifont preferredfontfortextstyle:uifonttextstylebody]}]; _textview.attributedtext = s1; 

however, when use nsmutableattributedstring see appended attributed strings without formatting. formatting shown string initialized only.

uifont *font = [uifont preferredfontfortextstyle:uifonttextstylebody]     nsmutableattributedstring *emailbody = [[nsmutableattributedstring alloc] initwithstring:@"" attributes:@{nsforegroundcolorattributename:[uicolor redcolor], nsfontattributename: font}]; if (_person.firstname.length > 0) {     [emailbody appendattributedstring:[[nsattributedstring alloc]initwithstring:_person.firstname attributes:@{nsfontattributename: [uifont preferredfontfortextstyle:uifonttextstylecaption1]}]];     [emailbody appendattributedstring:[[nsattributedstring alloc]initwithstring:@"\n" attributes:nil]]; } if (_person.lastname.length > 0) {     [emailbody appendattributedstring:[[nsattributedstring alloc]initwithstring:_person.lastname attributes:@{nsfontattributename: [uifont preferredfontfortextstyle:uifonttextstylecaption2]}]];     [emailbody appendattributedstring:[[nsattributedstring alloc]initwithstring:@"\n" attributes:nil]]; } 

why?

when nsattributedstring appended nsmutableattributedstring, has own attributes.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

debian - 500 Error upon login into Plesk Admin - auth.php3? -