SCLAlertView-Swift
SCLAlertView-Swift copied to clipboard
How to make button unable to click if the textfield don't have anything?
Hi,
I need with Swift version. I know how to do this with the UIAlertView.
I have functio to track:
func nameFieldDidChange(_ textField:UITextField){
self.currentAction.isEnabled = (textField.text?.characters.count)! > 0
}
Then I have something in my alertfunc:
alert.addAction(saveAction)
saveAction.isEnabled = false
self.currentAction = saveAction
currentaction is a bool type.
How can I do it with SCLAlertView?
Did you try something like this?
let txt = alert.addTextField("Enter your name")
txt.delegate = self
btn = alert.addButton("Show Name") {
print("Text value: \(txt.text ?? "NA")")
}
And set btn.isEnabled in UITextField delegate methods.