Permalink
Browse files

Try to mimic the UITableViewCellStyleValue2 if the cell is inited wit…

…h that style.
  • Loading branch information...
1 parent 9c88c83 commit 3e640e81b5d3b1be14b3d6a5811afd9cb6e69e75 James Van Metre committed Nov 8, 2013
Showing with 34 additions and 17 deletions.
  1. +29 −11 Classes/ELCTextFieldCell.m
  2. +5 −6 Classes/RootViewController.m
View
@@ -38,21 +38,39 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
if (self) {
self.leftLabel = [[UILabel alloc] initWithFrame:CGRectZero];
- [_leftLabel setBackgroundColor:[UIColor clearColor]];
- [_leftLabel setTextColor:[UIColor colorWithRed:.285 green:.376 blue:.541 alpha:1]];
- [_leftLabel setFont:[UIFont fontWithName:@"Helvetica" size:17]];
- [_leftLabel setTextAlignment:NSTextAlignmentCenter];
+ self.leftLabel.backgroundColor = [UIColor clearColor];
+ self.leftLabel.textAlignment = NSTextAlignmentRight;
[self addSubview:_leftLabel];
self.rightTextField = [[ELCInsetTextField alloc] initWithFrame:CGRectZero];
- _rightTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
- [_rightTextField setDelegate:self];
- [_rightTextField setFont:[UIFont systemFontOfSize:17]];
-
+ self.rightTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
+ self.rightTextField.delegate = self;
//Use Done for all of them.
- [_rightTextField setReturnKeyType:UIReturnKeyDone];
-
- [self addSubview:_rightTextField];
+ self.rightTextField.returnKeyType = UIReturnKeyDone;
+ [self addSubview:_rightTextField];
+
+ //Try to mimic the style of UITableViewCellStyleValue2 if inited with that style
+ if (style == UITableViewCellStyleValue2) {
+ //If iOS 7 and set up as UITableViewCellStyleValue2
+ if ([self respondsToSelector:@selector(tintColor)]) {
+ self.leftLabel.font = self.textLabel.font;
+ self.leftLabel.textColor = self.textLabel.textColor;
+ self.rightTextField.font = self.detailTextLabel.font;
+
+ //iOS 6 and below returns a 0 font size for the detailTextLabel.font
+ //So Revert to hard coding in the font and color in iOS 6 and below
+ } else {
+ self.leftLabel.font = [UIFont boldSystemFontOfSize:12];
+ self.leftLabel.textColor = [UIColor colorWithRed:.285 green:.376 blue:.541 alpha:1];
+ self.rightTextField.font = [UIFont boldSystemFontOfSize:15];
+ }
+
+ //Otherwise have a sane default
+ } else {
+ self.leftLabel.font = [UIFont systemFontOfSize:17];
+ self.leftLabel.textColor = [UIColor colorWithRed:.285 green:.376 blue:.541 alpha:1];
+ self.rightTextField.font = [UIFont systemFontOfSize:17];
+ }
}
return self;
@@ -75,13 +75,12 @@ - (void)configureCell:(ELCTextFieldCell *)cell atIndexPath:(NSIndexPath *)indexP
cell.rightTextField.placeholder = [self.placeholders objectAtIndex:indexPath.row];
cell.indexPath = indexPath;
cell.delegate = self;
- //Disables UITableViewCell from accidentally becoming selected.
- cell.selectionStyle = UITableViewCellEditingStyleNone;
+ //Disables UITableViewCell from accidentally becoming selected.
+ cell.selectionStyle = UITableViewCellEditingStyleNone;
- if(indexPath.row == 3) {
-
- [cell.rightTextField setKeyboardType:UIKeyboardTypeNumberPad];
+ if (indexPath.row == 3) {
+ [cell.rightTextField setKeyboardType:UIKeyboardTypeNumberPad];
}
}
@@ -104,7 +103,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
ELCTextFieldCell *cell = (ELCTextFieldCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
- cell = [[ELCTextFieldCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
+ cell = [[ELCTextFieldCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier];
}
[self configureCell:cell atIndexPath:indexPath];

0 comments on commit 3e640e8

Please sign in to comment.