When deleting a character from UITextField, the cursor does not stay in the same place, but moves to the end of the line

+38 (gray) is a mask that is added as soon as the user begins to enter a number

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { if textField == self.textField { let returnKey = (string as NSString).length == 0 let oldLength = textField.text!.length let replacementLength = string.length let rangeLength = range.length let newLength = oldLength - rangeLength + replacementLength return newLength <= 18 || returnKey } return true } } 

the cursor jumped to the end of the line

  • I understand the question is what should. show the code, in particular shouldChangeCharactersIn - Max Mikheyenko
  • @MaxMikheyenko enclosed the code to the question, but the point is that italics should remain at the place where the character was removed, and not jump to the end of the line - user235789
  • one
    Look at the answer here: stackoverflow.com/questions/34922331/… - Vitali Eller

0