Skip to content

Instantly share code, notes, and snippets.

@KanshuYokoo
Created September 13, 2018 07:55
Show Gist options
  • Save KanshuYokoo/82673ef4d05b1aa985601035cf973fa0 to your computer and use it in GitHub Desktop.
Save KanshuYokoo/82673ef4d05b1aa985601035cf973fa0 to your computer and use it in GitHub Desktop.
ios swift button enable with multiple textfields
class ViewController: UIViewController,UITextFieldDelegate {
@IBOutlet weak var text1: UITextField!
@IBOutlet weak var text2: UITextField!
@IBOutlet weak var button1Outlet: UIButton!
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
var t1 = text1.text
if(textField.tag == 0){
print(string)
t1 = (text1.text! as NSString).replacingCharacters(in: range, with: string)
os_log("%@", "text1 is \(String(describing: t1))")
}
var t2 = text2.text
if(textField.tag == 1){
print(string)
t2 = (text2.text! as NSString).replacingCharacters(in: range, with: string)
os_log("%@", "text2 is \(String(describing: t2))")
}
let isButtonActive = (t1?.isEmpty)! || (t2?.isEmpty)!
button1Outlet.isEnabled = !isButtonActive
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment