Skip to content

Instantly share code, notes, and snippets.

@piersadrian
Created October 27, 2013 16:38
Show Gist options
  • Save piersadrian/7184689 to your computer and use it in GitHub Desktop.
Save piersadrian/7184689 to your computer and use it in GitHub Desktop.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID];
if (! cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseID];
cell = [self addLabelsToCell:cell];
}
NSDictionary *client = [[clientTypes objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
[(UILabel *)[cell viewWithTag:0] setText:[client objectForKey:@"client"]];
[(UILabel *)[cell viewWithTag:1] setText:[NSString stringWithFormat:@"$%@", [client objectForKey:@"amount"]]];
[cell.contentView layoutIfNeeded];
return cell;
}
- (UITableViewCell *)addLabelsToCell:(UITableViewCell *)cell
{
UILabel *name = [UILabel new];
name.font = [UIFont systemFontOfSize:18];
name.textColor = [UIColor blackColor];
name.tag = 0;
[cell.contentView addSubview:name];
UILabel *amount = [UILabel new];
amount.font = [UIFont systemFontOfSize:12];
amount.textColor = [UIColor grayColor];
amount.tag = 1;
[cell.contentView addSubview:amount];
[name alignCenterYWithView:cell.contentView predicate:nil];
[name alignLeadingEdgeWithView:cell.contentView predicate:@"15"];
[amount alignCenterYWithView:cell.contentView predicate:nil];
[amount constrainLeadingSpaceToView:name predicate:@"20"];
return cell;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment