在textview iOS中的属性字符串末尾添加一个nsstring

Pol*_*les 3 objective-c nsstring nsattributedstring ios

我有一个像" Hello There "这样的文本,它将是一个红色的属性字符串.然后在该属性字符串的末尾,我想附加一个nsstring'你是谁?' 但每当我附加一个nsstring时,整个字符串就变成了普通的nsstring,并且删除了属性字符串的属性.我到目前为止的尝试:

NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:@"Hello There"];
[attributeString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,[attributeString length])];

NSMutableAttributedString *previousAttrString = [[NSMutableAttributedString alloc] initWithString:messageTextView.text];

[previousAttrString insertAttributedString: attributeString atIndex:location];
messageTextView.attributedText = previousAttrString;
messageTextView.font = [UIFont fontWithName:@"Helvetica" size:15];

NSString *messageWithContact = [NSString stringWithFormat: @"%@ %@", messageTextView.text, @"Who are you?"];
messageTextView.text=messageWithContact;
Run Code Online (Sandbox Code Playgroud)

我做错了什么?请帮我.

SGD*_*Dev 9

替换底线

NSString *messageWithContact = [NSString stringWithFormat: @"%@ %@", messageTextView.text, @"Who are you?"];
messageTextView.text=messageWithContact;
Run Code Online (Sandbox Code Playgroud)

NSMutableAttributedString *newString = messageTextView.attibutedText;
[newString appendAttributedString: [[NSAttributedString alloc] initWithString: @"Who are you?"];
messageTextView.attibutedText = newString;
Run Code Online (Sandbox Code Playgroud)