5 // Created by Mike Mayo on 1/19/11.
6 // Copyright 2011 __MyCompanyName__. All rights reserved.
9 #import "RSTextFieldCell.h"
10 #import "UIColor+MoreColors.h"
13 @implementation RSTextFieldCell
15 @synthesize textField, modalPresentationStyle, fixedTextLabel;
17 - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
18 self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
20 [self initializeSubviews:style withFixedTextLabel:nil];
25 - (id)initCellWithFixedLabel:(NSString *)fixedLabelText withStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
26 self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
28 [self initializeSubviews:style withFixedTextLabel:fixedLabelText];
33 - (void)initializeSubviews:(UITableViewCellStyle)style withFixedTextLabel:(NSString *)fixedLabelText {
34 self.selectionStyle = UITableViewCellSelectionStyleNone;
36 textField = [[UITextField alloc] initWithFrame:self.detailTextLabel.frame];
37 textField.textAlignment = self.detailTextLabel.textAlignment;
38 textField.returnKeyType = UIReturnKeyDone;
39 textField.backgroundColor = [UIColor clearColor];
40 textField.adjustsFontSizeToFitWidth = NO;
41 textField.autocorrectionType = UITextAutocorrectionTypeNo;
42 textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
44 if (style == UITableViewCellStyleValue1) {
45 textField.font = [UIFont systemFontOfSize:17.0];
46 } else if (style == UITableViewCellStyleValue2) {
47 textField.font = [UIFont boldSystemFontOfSize:15.0];
50 textField.textColor = self.detailTextLabel.textColor;
51 [self addSubview:textField];
53 self.detailTextLabel.textColor = [UIColor clearColor];
54 self.detailTextLabel.backgroundColor = [UIColor clearColor];
55 self.detailTextLabel.highlightedTextColor = [UIColor clearColor];
56 self.detailTextLabel.text = @"Using a very long string here to make sure that the UILabel is rendered at the maximum width so we can copy it for the UITextField.";
59 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
60 fixedTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(21.0, 14.5, 458.0, 18.0)];
62 fixedTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(21.0, 14.5, 280.0, 18.0)];
64 fixedTextLabel.font = [UIFont systemFontOfSize:17.0];
65 fixedTextLabel.textColor = [UIColor value1DetailTextLabelColor];
66 fixedTextLabel.backgroundColor = [UIColor clearColor];
67 fixedTextLabel.textAlignment = UITextAlignmentRight;
68 fixedTextLabel.text = fixedLabelText;
69 [self addSubview:fixedTextLabel];
74 - (void)drawRect:(CGRect)rect {
75 [super drawRect:rect];
77 CGRect aRect = self.detailTextLabel.frame;
79 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
80 if (modalPresentationStyle == UIModalPresentationFormSheet) {
81 textField.frame = CGRectMake(aRect.origin.x + 31.0, aRect.origin.y + 1.0, aRect.size.width - 24, aRect.size.height);
83 textField.frame = CGRectMake(aRect.origin.x + 35.0, aRect.origin.y + 1.0, aRect.size.width - 24, aRect.size.height);
86 textField.frame = CGRectMake(aRect.origin.x + 10.0, aRect.origin.y + 1.0, aRect.size.width, aRect.size.height);
91 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
95 CGSize fixedLabelTextSize = [fixedTextLabel.text sizeWithFont:fixedTextLabel.font constrainedToSize:CGSizeMake(280.0, 900.0f)];
96 textField.frame = CGRectMake(textField.frame.origin.x,
97 textField.frame.origin.y,
98 textField.frame.size.width - fixedLabelTextSize.width + xOffset,
99 textField.frame.size.height);
102 // this isn't generic. this is for text decoration on the end of the textField
103 if (self.accessoryView) {
104 aRect = textField.frame;
105 aRect.origin.x += 9.0;
106 textField.frame = aRect;
109 textField.contentStretch = self.detailTextLabel.contentStretch;
110 textField.backgroundColor = [UIColor clearColor];
111 textField.transform = self.detailTextLabel.transform;
112 textField.clipsToBounds = self.detailTextLabel.clipsToBounds;
113 textField.clearsContextBeforeDrawing = self.detailTextLabel.clearsContextBeforeDrawing;
114 textField.contentMode = self.detailTextLabel.contentMode;
115 textField.autoresizingMask = self.detailTextLabel.autoresizingMask;
116 textField.autoresizesSubviews = YES;
117 textField.font = self.detailTextLabel.font;
122 [fixedTextLabel release];