Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…h that style.
  • Loading branch information...
commit 3e640e81b5d3b1be14b3d6a5811afd9cb6e69e75 1 parent 9c88c83
James Van Metre authored
Showing with 34 additions and 17 deletions.
  1. +29 −11 Classes/ELCTextFieldCell.m
  2. +5 −6 Classes/RootViewController.m
View
40 Classes/ELCTextFieldCell.m
@@ -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;
View
11 Classes/RootViewController.m
@@ -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];
Please sign in to comment.
Something went wrong with that request. Please try again.