简体   繁体   中英

How can you group characters in a UITextView to be treated as a single character

In my UITextView I'd like for certain words to be treated as "chunked" or "segments" that:

  1. Can't be selected mid-word
  2. If backspaced will delete the entire word

A good example of this is the Facebook composing post screen that allows you to mention Facebook friends but if you try to delete the mention, the whole name goes away, not just a single letter.

Of all the text-kit and core text classes, is there one that fits this use-case well?

I guess You can use NSTextAttachments since they're treated as a single character. Here is what I found in the doc:-

A text attachment object contains an NSFileWrapper object, which in turn holds the contents of the attached file. It also uses a cell object conforming to the NSTextAttachmentCell protocol to draw and handle mouse events. Most of the behavior of a text attachment is relegated to the file wrapper and the attachment cell. See the corresponding class and protocol specifications for more information.

You can use this to add small images in text view text as well.

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