mardi 24 mars 2015

Keep the colors of the textView text after appending NSSting

I'm using the next method to change the colors of few words in textView:



+(void)changeColorToTextObject : (UITextView *)textView ToColor : (UIColor *)color FromLocation : (int)location length : (int)length
{
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithAttributedString: textView.attributedText];

[text addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(location, length)];
[textView setAttributedText: text];
}


and it looks like this: enter image description here


but when i'm adding new value to this text the color are gone.


myTextView.text = [myTextView.text stringByAppendingString:newStr];


And it looks like this:


enter image description here


How can I keep the colors like before with the new string?




Aucun commentaire:

Enregistrer un commentaire