-
Notifications
You must be signed in to change notification settings - Fork 0
/
AmountEditor.m
95 lines (79 loc) · 3.02 KB
/
AmountEditor.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// AmountEditor.m
// Allowance
//
// Created by Pablo Collins on 6/22/10.
//
#import "AmountEditor.h"
@implementation AmountEditor
@synthesize currencyLabel;
@synthesize decimalLabel;
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 5;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return 10;
}
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
return 45;
}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {
return 42;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [NSString stringWithFormat:@"%d",9-row];
}
- (void)viewDidLoad {
[super viewDidLoad];
int n0 = payAmount / 10000;
int n1 = (payAmount % 10000) / 1000;
int n2 = (payAmount % 1000) / 100;
int n3 = (payAmount % 100) / 10;
int n4 = payAmount % 10;
[amountPicker selectRow:9-n0 inComponent:0 animated:NO];
[amountPicker selectRow:9-n1 inComponent:1 animated:NO];
[amountPicker selectRow:9-n2 inComponent:2 animated:NO];
[amountPicker selectRow:9-n3 inComponent:3 animated:NO];
[amountPicker selectRow:9-n4 inComponent:4 animated:NO];
UIImage *blueImage = [UIImage imageNamed:@"blueButton.png"];
UIImage *whiteImage = [UIImage imageNamed:@"whiteButton.png"];
CGRect f1 = CGRectMake(30, 300, 260, 40);
UIButton *btn = [AllowanceAppDelegate newButtonWithTitle:@"OK"
target:self
selector:@selector(save:)
frame:f1
image:whiteImage
imagePressed:blueImage
darkTextColor:YES];
[self.view addSubview:btn];
currencyLabel.text = [[AllowanceAppDelegate currencyFormatter] currencySymbol];
if ([AllowanceAppDelegate numCentPlaces] == 0) {
decimalLabel.text = @"";
} else {
decimalLabel.text = [[AllowanceAppDelegate currencyFormatter] currencyDecimalSeparator];
}
}
- (void)setAmount:(int)amount {
payAmount = amount;
}
- (void)setCallback:(SEL)sel withObject:(NSObject *)object {
callback = sel;
callbackObject = object;
}
- (int)amount {
return [self valueAtPosition:0] + [self valueAtPosition:1] + [self valueAtPosition:2] +
[self valueAtPosition:3] + [self valueAtPosition:4];
}
- (void)save:(id)sender {
[callbackObject performSelector:callback withObject:[NSNumber numberWithInt:[self amount]]]; //foo
[self.navigationController popViewControllerAnimated:YES];
}
- (void)cancel:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
- (int)valueAtPosition:(int)pos {
int v = 9 - [amountPicker selectedRowInComponent:pos];
int p = 4 - pos;
return v * pow(10.0, p);
}
@end