I've had exactly the same problem, except half way through implementation we decided to scrap the design and went for custom tableview cells instead. Our original design was meant to look like a notepad, with cells on each line.
Subclassing a UITableViewCell might seem like a difficult task but its worth it if you will need to customise the cell in the future and seems like it will do what you are requesting. I can post the code for you from my project if you are interested, However, be aware that you will not have the background on the UITableView itself, only on the cells.
EDIT: Posting the code related to creation of custom UITableViewCell:
My cell is called HotOffersCell,
This is HotOffersCell.h
#import <UIKit/UIKit.h>
@interface HotOffersCell : UITableViewCell {
IBOutlet UILabel *mainLabel;
IBOutlet UILabel *subLabel;
IBOutlet UILabel *price;
IBOutlet UIImageView *imageView;
}
@property (nonatomic, retain) UILabel *mainLabel;
@property (nonatomic, retain) UILabel *subLabel;
@property (nonatomic, retain) UILabel *price;
@property (nonatomic, retain) UIImageView *imageView;
@end
HotOffersCell.m is very plain, just sysnthesize for all the properties, nothing else
Then in the TableView method of your table view controller:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"HotOffersCell";
HotOffersCell *cell = (HotOffersCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"HotOffersCell" owner:nil options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[UITableViewCell class]]) {
cell = (HotOffersCell *) currentObject;
break;
}
}
}
NewsItem *newsItem = [newsList objectAtIndex:indexPath.row];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"d MMM YY"];
NSString *date = [formatter stringFromDate:newsItem.departure_date];
if (indexPath.row % 2 == 0) {
cell.contentView.backgroundColor = [UIColor colorWithWhite:230.0/255 alpha:1]; // Match Colour
} else {
cell.contentView.backgroundColor = [UIColor colorWithWhite:242.0/255 alpha:1]; // Match Colour
}
cell.mainLabel.text = newsItem.destination;
cell.subLabel.text = [[NSString alloc] initWithFormat:@"%@ - %@ nights", date, newsItem.nights];
if ([self.navigationController.title isEqualToString:@"Top 20"]) {
cell.price.text = newsItem.price_inside;
} else {
cell.price.text = newsItem.price_balcony;
}
cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.png", newsItem.cruise_line]];
[formatter release];
return cell;
}
I also have a HotOffersCell.xib, This file contains a UITableViewCell and no view, i've linked all the relevant labels around and nothing more, It provides a nice graphical way to edit the placements on the label without changes in code, I even let my brother modify this one =)
I hope this helps