I used this approach in a game i an developing.
You subclass UITableViewCell, then you add a UIImageView and UILabel to the cell programatically. this gives you a great way to customize the look of your cell.
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
// Initialization code
headerLabel = [[UILabel alloc]init];
headerLabel.textAlignment = UITextAlignmentLeft;
imageV = [[UIImageView alloc] init];
descriptionLabel.font = [UIFont fontWithName:@"Marker Felt" size:14];
descriptionLabel = [[UILabel alloc]init];
descriptionLabel.textAlignment = UITextAlignmentLeft;
descriptionLabel.font = [UIFont fontWithName:@"Marker Felt" size:11];
descriptionLabel.lineBreakMode = UILineBreakModeWordWrap;
descriptionLabel.numberOfLines = 0;
[self.contentView addSubview:headerLabel];
[self.contentView addSubview:descriptionLabel];
[self.contentView addSubview:imageV];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
CGRect frame;
frame= CGRectMake(boundsX+60 ,3, 200, 15);
headerLabel.frame = frame;
frame= CGRectMake(boundsX+60 ,18, 260, 39);
descriptionLabel.frame = frame;
frame= CGRectMake(boundsX+3 , 3, 54, 54);
imageV.frame = frame;
}
Also you will have to change a method in the UITableView class:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = @"Cell";
AchievementCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[AchievementCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
[cell returnCellAtIndex:indexPath.row];
[cell returnImageAtIndex:indexPath.row];
return cell;
}
Feel free to ask any more questions regarding the code :)