iOS: Programmatically move cursor up, down, left and right in UITextView
I use the following code to move the cursor position to 5 characters from the beginning of a UITextField : txtView.selectedRange = NSMakeRange(5, 0); Now, if I have a cursor at an arbitrary position as shown in the image below, how can I move the cursor up, down, left and right? Left and right should be more or less easy. I guess the tricky part is top and bottom. I would try the following. You can use caretRect method to find the current "frame" of the cursor: if let cursorPosition = answerTextView.selectedTextRange?.start { let caretPositionRect = answerTextView.caretRect(for: cursorPosition