NSMutableAttributedString:如何在 iOS 上以编程方式删除最后一个字符? [英] NSMutableAttributedString: How to delete last character programmatically on iOS?
本文介绍了NSMutableAttributedString:如何在 iOS 上以编程方式删除最后一个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个自定义键盘,我必须对具有 nsmutableattributed 字符串作为文本(字符和 nstextattachments 的组合)的 textview 执行退格操作
I have a custom keyboard and I have to perform backspace action on textview having nsmutableattributed string as a text (combination of character and nstextattachments)
推荐答案
根据 Moxy:如果您的最后一个字符大到无法容纳在单个 UTF-16 单元中,那么 Dave 的方法将只是截断该字符的描述.表情符号就是一个例子 但还有更多.
As per Moxy: if your last character is large enough not to fit within a single UTF-16 unit then Dave's method will just truncate the description of that character. Emojis are an example but there are a bunch more.
所以你更有可能想要:
[string deleteCharactersInRange:
[string.string rangeOfComposedCharacterSequenceAtIndex:string.length - 1]]
这篇关于NSMutableAttributedString:如何在 iOS 上以编程方式删除最后一个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文