Skip to content

Instantly share code, notes, and snippets.

Created September 26, 2011 14:57
Show Gist options
  • Save anonymous/1242422 to your computer and use it in GitHub Desktop.
Save anonymous/1242422 to your computer and use it in GitHub Desktop.
implementation of tableView:cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
CGFloat side = cell.contentView.bounds.size.height;
UIImageView* iv = [[UIImageView alloc] init];
iv.frame =
CGRectMake(cell.contentView.bounds.size.width - side, 0, side, side);
iv.tag = 1;
iv.autoresizingMask = UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleLeftMargin;
[cell.contentView addSubview:iv];
[iv release];
UILabel* lab = [[UILabel alloc] init];
lab.frame =
CGRectMake(5, 0, cell.contentView.bounds.size.width - side - 10, side);
lab.tag = 2;
lab.autoresizingMask = UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleRightMargin;
[cell.contentView addSubview:lab];
[lab release];
}
UILabel* lab = (UILabel*)[cell viewWithTag: 2];
lab.text = @"label";
lab.font = [UIFont fontWithName:@"Helvetica-Bold" size:16];
lab.lineBreakMode = UILineBreakModeWordWrap;
lab.numberOfLines = 2;
lab.textColor = [UIColor whiteColor];
// can now do this here, because framework won't change it later
lab.backgroundColor = [UIColor clearColor];
UIImageView* iv = (UIImageView*)[cell viewWithTag: 1];
UIImage* im = [UIImage imageNamed:@"moi.png"];
UIGraphicsBeginImageContextWithOptions(CGSizeMake(35,35), YES, 0.0);
[im drawInRect:CGRectMake(0,0,35,35)];
UIImage* im2 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
iv.image = im2;
iv.contentMode = UIViewContentModeCenter;
return cell;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment