Skip to content

Instantly share code, notes, and snippets.

@spotlessicode
Created November 13, 2014 14:36
Show Gist options
  • Save spotlessicode/113db53a2ead9739177f to your computer and use it in GitHub Desktop.
Save spotlessicode/113db53a2ead9739177f to your computer and use it in GitHub Desktop.
- (void)textFieldDidBeginEditing:(UITextField *)textField {
// When start to edit the placeholder will disappear
self.TextField1.placeholder = @"";
self.TextField2.placeholder = @"";
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
//When editing end which text show in the TexField placeholder
if (self.TextField1.text.length == 0) {
self.TextField1.text = self.TextField1.placeholder;
}
self.TextField1.placeholder = self.TextField1.text;
if (self.TextField2.text.length == 0) {
self.TextField2.text = self.TextField2.placeholder;
}
self.TextField2.placeholder = self.TextField2.text;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
//Keyboard Return button - end editing, dismiss keyboard
[textField resignFirstResponder];
return YES;
}
-(void) touchesBegan :(NSSet *) touches withEvent:(UIEvent *)event
{
// If you touch otside of TextField your editing will stop adn keyboard dismiss
[self.TextField1 resignFirstResponder];
[self.TextField2 resignFirstResponder];
[super touchesBegan:touches withEvent:event ];
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment