Search code examples
iosobjective-ccursoruitextview

Move Cursor One Word(including language like Chinese) at a Time in UTextView


I have read this,but it can only work well in English for it just use white-space and something like NewlineCharacterSet as separator. I want to add a left arrow and a right arrow in the accessory input view to move the cursor in UITextView by words. And I am wondering how to support that feature for some Asian languages like Chinese

PS:I will added an example that CFStringTokenizer failed to work with when there are both English Characters and Chinese characters

test string: 
Happy Christmas! Text view test 云存储容器测试开心 yeap
the expected boundaries: 
Happy/ Christmas!/ Text/ view/ test/ 云/存储/容器/测试/开心/ yeap/
the boundaries show in reality: 
Happy/ Christmas!/ Text/ view/ test/ 云存储容器测试开心/ yeap/

Solution

  • Finnally I use UITextInputTokenizer to realized the function