Created
August 30, 2012 14:03
-
-
Save henriquegogo/3529171 to your computer and use it in GitHub Desktop.
Extending UITextField to reuse some behaviours
This file contains hidden or 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
#import "UITextFieldNumber.h" | |
@implementation UITextFieldNumber | |
- (void)awakeFromNib | |
{ | |
[self createKeyboardToolbar]; | |
} | |
- (void)createKeyboardToolbar | |
{ | |
UIToolbar *toolbarView = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 35)]; | |
toolbarView.tintColor = [UIColor blackColor]; | |
toolbarView.translucent = YES; | |
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Fechar" style:UIBarButtonItemStyleDone target:self action:@selector(closeKeyboard)]; | |
[toolbarView setItems:[NSArray arrayWithObject:doneButton]]; | |
self.inputAccessoryView = toolbarView; | |
} | |
- (void)closeKeyboard | |
{ | |
[self resignFirstResponder]; | |
} | |
- (void)textFieldDidEndEditing:(UITextField *)textField | |
{ | |
NSLog(@"Digitou mesmo"); | |
} | |
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string | |
{ | |
NSLog(@"Digitando"); | |
return YES; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment