How do I restore the style after UITextView, is inserted into attributeString?

problem description

after textView append an attributeString with the code, continue to edit the keyboard, the style cannot be restored

related codes

The code for

button is as follows:

let attributeText = NSMutableAttributedString(attributedString: textView.attributedText)
attributeText.append(NSAttributedString(string: "@", attributes: [NSAttributedString.Key.foregroundColor: UIColor.cyan]))
self.textView.attributedText = attributeText

what result do you expect? What is the error message actually seen?

I want textView to revert to its original style when it is re-edited


has found the answer. You can set the typingAttributes of textView in shouldChangeTextIn to reset to the previous style

Menu