Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
UITextField delegate
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