Skip to content

Instantly share code, notes, and snippets.

@alokc83
Created May 2, 2018 19:28
Show Gist options
  • Save alokc83/ab7b7cd8803aa831ebfc816c574e6a8b to your computer and use it in GitHub Desktop.
Save alokc83/ab7b7cd8803aa831ebfc816c574e6a8b to your computer and use it in GitHub Desktop.
when need to disable the button on the alert viewController.
// another solution of disabling the button
//where alert is variable in class
override func textField(_ textField: UITextField,
shouldChangeCharactersIn range: NSRange,
replacementString string: String) -> Bool {
if range.location >= 1 { return true } // if we have one or more characters
guard let isTextFieldEmpty = textField.text?.isEmpty else { return true }
if !isTextFieldEmpty {
alert?.actions.first?.isEnabled = false
} else {
alert?.actions.first?.isEnabled = true
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment