问题描述
在 textView 用代码 append 一个 attributeString 后,继续键盘编辑,样式不能恢复
相关代码
button 的代码如下:
let attributeText = NSMutableAttributedString(attributedString: textView.attributedText)
attributeText.append(NSAttributedString(string: "@黄小小", attributes: [NSAttributedString.Key.foregroundColor: UIColor.cyan]))
self.textView.attributedText = attributeText
你期待的结果是什么?实际看到的错误信息又是什么?
希望 textView 重新编辑的时候恢复成开始的样式
找到答案了,可以在 shouldChangeTextIn 里设置 textView 的 typingAttributes 重设成之前的样式