Control cursor position in UITextField

Controlling cursor position in a UITextField is complicated because so many abstractions are involved with input boxes and calculating positions. However, it’s certainly possible. You can use the member function setSelectedTextRange: [input setSelectedTextRange:[input textRangeFromPosition:start toPosition:end]]; Here’s a function which takes a range and selects the texts in that range. If you just want to place … Read more

Getting and Setting Cursor Position of UITextField and UITextView in Swift

The following content applies to both UITextField and UITextView. Useful information The very beginning of the text field text: let startPosition: UITextPosition = textField.beginningOfDocument The very end of the text field text: let endPosition: UITextPosition = textField.endOfDocument The currently selected range: let selectedRange: UITextRange? = textField.selectedTextRange Get cursor position if let selectedRange = textField.selectedTextRange { … Read more