Skip to content

Instantly share code, notes, and snippets.

@henriquegogo
Created August 30, 2012 14:03
Show Gist options
  • Save henriquegogo/3529171 to your computer and use it in GitHub Desktop.
Save henriquegogo/3529171 to your computer and use it in GitHub Desktop.
Extending UITextField to reuse some behaviours
#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