Answers for "on edit input field provide default value if textfield get empty swift"

0

on edit input field provide default value if textfield get empty swift

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
    guard let textFieldString = textField.text, let range = Range(range, in: textFieldString) else {
        return false
    }
    let newString = textFieldString.replacingCharacters(in: range, with: string)
    if newString.isEmpty {
        textField.text = "0"
        return false
    } else if textField.text == "0" {
        textField.text = string
        return false
    }
    return true
}
Posted by: Guest on January-16-2022

Code answers related to "on edit input field provide default value if textfield get empty swift"

Code answers related to "Swift"

Browse Popular Code Answers by Language