UITextPosition not working correctly in iOS 13.6 and above

133 Views Asked by At

I am working with UITextField with an existing text in it. I want to cursor appear at the beginning of the text when I focus on UITextField. Everything worked fine before I changed the version of iOS to 13.6

I want it to be like this: (iOS13.1)

screen1

But instead I get this: (iOS13.6)

screen2

Below is my code.

override func viewDidLoad() {
    super.viewDidLoad()

    textField.delegate = self
    textField.text = "Some text"
}

func textFieldDidBeginEditing(_ textField: UITextField) {
    let newPosition = textField.beginningOfDocument
    textField.selectedTextRange = textField.textRange(from: newPosition, to: newPosition)

}

I tried to set cursor position to the center. It also did not work. Is it an iOS bug? or am I doing something wrong? Also, is there another version to set cursor of UITextField?

0

There are 0 best solutions below