UITextInput: selectedTextRange vs. markedTextRange?

对着背影说爱祢 提交于 2019-12-04 06:08:17

From Apple documentation for UITextInput:

Marked text, which is part of multistage text input, represents provisionally inserted text that the user has yet to confirm. It is styled in a distinctive way. The range of marked text always contains within it a range of selected text, which might be a range of characters or the caret.

Hence markedTextRange gets useful with languages that requires multistage input, e.g. Japanese. In simple words: what user types is yet to be confirmed before it can be added to the value of the text input control is were markedTextRange gets into the game. GIF bellow demonstrates markedTextRange in action:

Notice slight sapphire background behind the unconfirmed hieroglyphs. Once text gets confirmed either by hitting enter/return, selecting option from suggestions or finger tap on text area after the marked text gets added to the input control value and background gets removed.

Notes:

  • markedTextRange has nothing to do with read-only text
  • I was not able to achieve multiple symbols selection within markedTextRange
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!