Created
September 1, 2015 14:05
-
-
Save y8k/f6c02723b8b036b2231f to your computer and use it in GitHub Desktop.
UITextField delegate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func textFieldDidBeginEditing(textField: UITextField) { | |
self.showMessageToUser(nil) | |
} | |
func textFieldDidEndEditing(textField: UITextField) { | |
if textField.text?.characters.count <= 0 { | |
if let hasLabel = textField as? UTTextField { | |
hasLabel.changeStatus(.Normal) | |
} | |
} | |
} | |
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { | |
if string.characters.count == 0 { | |
if textField.text?.characters.count <= 1 { | |
if let hasLabel = textField as? UTTextField { | |
hasLabel.changeStatus(.Normal) | |
} | |
} | |
} | |
else { | |
if let hasLabel = textField as? UTTextField { | |
hasLabel.changeStatus(.Input) | |
} | |
} | |
return true | |
} | |
func textFieldShouldReturn(textField: UITextField) -> Bool { | |
if textField.isEqual(self.emailTextField) { | |
self.passwordTextField.becomeFirstResponder() | |
} | |
else { | |
textField.resignFirstResponder() | |
} | |
return false | |
} | |
func textFieldShouldClear(textField: UITextField) -> Bool { | |
if let hasLabel = textField as? UTTextField { | |
hasLabel.changeStatus(.Normal) | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment