Can you please help me.
In UITextField
when we provide a placeholder text its placeholder string will be gone when we enter any character. How can I achieve
Instead of using placeholder text, use a UILabel below your textfield and give the same font style to both. the label text should be like "- - - - -"
And when user starts typing on textfield give a space after each character press.
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if textField.text?.characters.count == 0 && string.characters.count != 0 {
textField.text = textField.text! + " "
}
else {
return false
}
if textField.text?.characters.count == 1 && string.characters.count != 0 {
textField.text = textField.text! + " "
}
else {
return false
}
if textField.text?.characters.count == 2 && string.characters.count != 0 {
textField.text = textField.text! + " "
}
else {
return false
}
if textField.text?.characters.count == 3 && string.characters.count != 0 {
textField.text = textField.text! + " "
}
else {
return false
}
return true
}