Uitextview set cursor position swift. The answer below i...
Uitextview set cursor position swift. The answer below is the the result of my experimentation and translation from My post from 2015 (Finding the Location of the Cursor in UITextView, UITextField), works great in objective C. But since I am working with Swift, I wanted to learn how to get the current cursor location and also set it in Swift. . becomeFirstResponder ()` to give focus to the text field and make the keyboard appear. Call the focus () method on the textarea element. But because the UITextView expands to show its entire contents, the cursor never occluded by the text This answer uses a text field, but the same concepts apply to `UITextView`. swift This answer uses a text field, but the same concepts apply to UITextView. Start at the beginning and move 5 characters to the right. How can I move the cursor there? To set the cursor at the end of a textarea: Use the setSelectionRange () method to set the current text selection position to the end of the textarea. Use `textView. becomeFirstResponder() to give focus to the text field and make the keyboard appear. However, here’s the UITextView methodology for Swift 3. Whenever the cursor moves, it would simply scroll itself so that the cursor is visible. 0. How to get UITextView cursor to end of string? Irrespective of where the textview has been tapped (iOS), I want that the cursor position is at the end of the string. Use textField. In order to set the position, all of these methods are actually setting a range with the same start and end values. If the text is only 1 line, the cursor position will be in the top left corner of UITextView, otherwise, if the text is longer than 1 line, the cursor position will be in the bottom left corner of UITextView. Live reload of text in UITextView while preserving cursor position and text selection - TextEditing.