-
Notifications
You must be signed in to change notification settings - Fork 5
/
DoneCancelNumberPadToolbar.m
56 lines (48 loc) · 1.88 KB
/
DoneCancelNumberPadToolbar.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// DoneCancelNumberPadToolbar.m
//
// Created by Timothy Broder on 8/17/12.
//
//
#import "DoneCancelNumberPadToolbar.h"
@implementation DoneCancelNumberPadToolbar
@synthesize delegate;
- (id) initWithTextField:(UITextField *)aTextField
{
return [self initWithTextField:aTextField withKeyboardType:UIKeyboardTypeNumberPad];
}
- (id) initWithTextField:(UITextField *)aTextField withKeyboardType:(int)keyboardType
{
self = [super initWithFrame:CGRectMake(0, 0, 320, 50)];
if (self) {
textField = aTextField;
[textField setKeyboardType:keyboardType];
self.barStyle = UIBarStyleDefault;
self.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:@"Cancel"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(cancelNumberPad)],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:@"Done"
style:UIBarButtonItemStyleDone
target:self
action:@selector(doneWithNumberPad)],
nil];
[self sizeToFit];
}
return self;
}
-(void)cancelNumberPad
{
[textField resignFirstResponder];
textField.text = @"";
[self.delegate doneCancelNumberPadToolbarDelegate:self didClickCancel:textField];
}
-(void)doneWithNumberPad
{
[textField resignFirstResponder];
[self.delegate doneCancelNumberPadToolbarDelegate:self didClickDone:textField];
}
@end