简体   繁体   中英

Remove NSAttributedString Attributes

I have a UITextView that upon initialization displays a string from a database and formats it using an NSAttributedString . This works fine. If the user clicks a 'New Entry' button, I need to clear the text view and allow the user to enter their own text. I do not want the attributes from the attributed string to follow along. (I just want an unformatted string). However, as soon as the user starts typing, their text is formatted like it was when it was displaying server data. I don't know how to reset this.

I've tried:

self.notes = @"";
self.notes = nil;

I thought that setting the field to nil would solve it for sure, but it doesn't. Can anyone tell me how to do this? Thank you.

将文本视图的typingAttributes属性设置为空字典(或者可能为nil )。

Try this to clear the Attributed feature

NSMutableAttributedString *originalMutableAttributedString = //users' string…
NSRange originalRange = NSMakeRange(0, originalMutableAttributedString.length);
[originalMutableAttributedString setAttributes:@{} range:originalRange];
textView.text = originalMutableAttributedString;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM