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)
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
So you'll more likely want:
[string deleteCharactersInRange:
[string.string rangeOfComposedCharacterSequenceAtIndex:string.length - 1]]
回答2:
Swift 4
mutableAttributedString.deleteCharacters(in: NSRange(location:(mutableAttributedString.length) - 1,length:1))