-
Notifications
You must be signed in to change notification settings - Fork 4
/
UTTableViewTextFieldCell.m
134 lines (102 loc) · 2.85 KB
/
UTTableViewTextFieldCell.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//
// UTTableViewTextFieldCell.m
// RingFinder
//
// Created by Danny Morrow on 10/29/10.
// Copyright 2010 unitytheory.com. All rights reserved.
//
#import "UTTableViewTextFieldCell.h"
#import "UTTableViewPListDataSource.h"
@implementation UTTableViewTextFieldCell
@synthesize textField = _textField;
- (void) drawView
{
[super drawView];
_textField = [[UITextField alloc] initWithFrame:CGRectZero];
_textField.textAlignment = NSTextAlignmentRight;
_textField.delegate = self;
_textField.adjustsFontSizeToFitWidth = TRUE;
_textField.minimumFontSize = 12;
[self addSubview:_textField];
}
- (void) layoutSubviews
{
[super layoutSubviews];
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.textLabel.backgroundColor = [UIColor clearColor];
CGSize labelSize = [self.textLabel sizeThatFits:CGSizeZero];
labelSize.width = MIN(labelSize.width, self.textLabel.bounds.size.width);
CGRect textFieldFrame = self.textLabel.frame;
textFieldFrame.origin.x = self.textLabel.frame.origin.x + MAX(kUTMinLabelWidth, labelSize.width) + kUTSpacing;
if (!self.textLabel.text.length)
{
textFieldFrame.origin.x = self.textLabel.frame.origin.x;
}
textFieldFrame.size.width = self.textField.superview.frame.size.width - textFieldFrame.origin.x - 2*self.textLabel.frame.origin.x;
if (self.accessoryView)
{
textFieldFrame.size.width -= self.accessoryView.frame.size.width + 5;
}
self.textField.frame = textFieldFrame;
}
- (void) setData:(NSDictionary *)d
{
super.data = d;
_textField.placeholder = [super.data valueForKey:@"Placeholder"];
_textField.secureTextEntry = [[super.data valueForKey:@"IsSecure"] boolValue];
}
- (float) fixedTextPosition
{
return 150;
}
#pragma mark -
#pragma mark textFieldDelegate
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
//textField.textAlignment = UITextAlignmentLeft;
if ([self.delegate respondsToSelector:@selector(cellDidBeginEditting:)])
{
[self.delegate cellDidBeginEditting:self];
}
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
self.value = textField.text;
//textField.textAlignment = UITextAlignmentRight;
if ([self.delegate respondsToSelector:@selector(cellDidEndEditting:)])
{
[self.delegate cellDidEndEditting:self];
}
}
- (void) setValue:(id)val
{
[super setValue:val];
[self updateText];
}
- (void) updateText
{
self.textField.text = self.value;
}
-(UIResponder *) responder
{
return self.textField;
}
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if ([string isEqualToString:@"\n"])
{
[textField resignFirstResponder];
[self textFieldDidEndEditing:textField];
if ([self.delegate respondsToSelector:@selector(cellDidSubmit:)])
{
[self.delegate cellDidSubmit:self];
}
return FALSE;
}
return TRUE;
}
- (void) select
{
[_textField becomeFirstResponder];
}
@end