简体   繁体   中英

How to clear custom smiley from UITextView

I have a UITextView with combination of text and custom smileys (Attached using NSTextAttachment). And I have a custom UIButton action in which I need to clear the single character from textview's text. My questions are below.

  1. How to find out whether it is text or NSTextAttachment at cursor location in UITextView.
  2. After finding, how to clear that single character or NSTextAttachment from that string.

I tried a lot, but couldn't get it. Any ideas please..

Thanks

  1. You can find the class of the object by using isKindOfClass method. This will tell you whether the object is of class NSTextAttachment or NSString .
  2. I am assuming you are using NSMutableAttributedString , if so then just find out the range of the character and delete it using deleteCharactersInRange: method of NSMutableAttributedString .

Try this:

-(IBAction)yourButton:(id)sender {
       yourUITextView.text = [NSString stringWithFormat:@" Your text here, omit the smiley."];
}

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