I want a ‘+’ Sign in the Textfield which cannot be erased. A user should be able to enter values after it and if he presses backspace it should only erase the v
Try replacing the "+" with my "kg"
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
var amountTypedString = myTF.text
if string.count > 0 {
if amountTypedString?.count ?? 0 > 2 {
amountTypedString = String((amountTypedString?.dropLast(2))!)
}
amountTypedString! += string
let newString = amountTypedString! + "kg"
myTF.text = newString
} else {
amountTypedString = String((amountTypedString?.dropLast(3))!)
if (amountTypedString?.count)! > 0 {
let newString = amountTypedString! + "kg"
myTF.text = newString
} else {
myTF.text = ""
}
}
return false
}