Custom Keyboard Set Cursor Position

爷,独闯天下 提交于 2019-12-04 20:37:06
Cyrus1

First get the initial position of the cursor (or the end of the selected range):

UITextRange *selectedRange = [textField selectedTextRange];
NSInteger offset = [textField offsetFromPosition:textField.endOfDocument toPosition:selectedRange.end];

After modifying the textField's text, reset the cursor position by using UITextPosition as follows:

UITextPosition *newPos = [textField positionFromPosition:textField.endOfDocument offset:offset];
textField.selectedTextRange = [textField textRangeFromPosition:newPos toPosition:newPos];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!