Maybe I can help.. this screen is from myApp. If this is something similar you want to achieve than here how I do it.
1) table view controller file
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//create my own cell view
ChannelTableViewCell *cell = (ChannelTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"ChannelTableViewCell"];
//create my view for cell bacground (just draw gradient)
ChannelTableCellBackgroundView *cellBgView = [[ChannelTableCellBackgroundView alloc] initWithFrame:CGRectZero];
cell.backgroundView = cellBgView;
[cellBgView release];
// .... other code continues ...
}
2. custom cell view code (subclass of UITableViewCell, this layouts labels images for tile view)
Code:
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
channel = nil;
channelTileView = nil;
labelView = nil;
// create the channelTileView and the labelView
// both of these will be laid out again by the layoutSubviews method
ChannelTileView *tileView = [[ChannelTileView alloc] initWithFrame:CGRectZero];
self.channelTileView = tileView;
[self.contentView addSubview:tileView];
[tileView release];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
// set the label view to have a clear background and a 20 point font
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont systemFontOfSize:18];
self.labelView = label;
[self.contentView addSubview:label];
[label release];
// add both the label and channelTile to the TableViewCell view
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
// determine the content rect for the cell. This will change depending on the
// style of table (grouped vs plain)
CGRect contentRect = self.contentView.bounds;
// position the image tile in the content rect.
CGRect channelTileRect = self.contentView.bounds;
channelTileRect.size = [ChannelTileView preferredViewSize];
channelTileRect = CGRectOffset(channelTileRect,10,9);
channelTileView.frame = channelTileRect;
// position the channel name in the content rect
CGRect labelRect = contentRect;
labelRect.origin.x = labelRect.origin.x+80;
labelRect.origin.y = labelRect.origin.y-1;
labelView.frame = labelRect;
}
3. and the code of custom background view (subclass of UIView, this just draws a simple gradient)
Code:
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// Initialization code
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGContextRef myContext = UIGraphicsGetCurrentContext();
CGGradientRef myGradient;
CGColorSpaceRef myColorspace;
size_t num_locations = 2;
CGFloat locations[2] = { 0.0, 1.0};
CGFloat components[8] = { 0.92, 0.92, 0.92, 1.0,
0.82, 0.82, 0.82, 1.0 };
myColorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
myGradient = CGGradientCreateWithColorComponents (myColorspace, components,
locations, num_locations);
CGPoint myStartPoint, myEndPoint;
myStartPoint.x = 0.0;
myStartPoint.y = 0.0;
myEndPoint.x = 1.0;
myEndPoint.y = 100.0;
CGContextDrawLinearGradient (myContext, myGradient, myStartPoint, myEndPoint, 0);
}
Hope you can help ourself with this. It's pretty straight forward all you need to do is:
- subclass UITableViewCell
- set cell.backgroundView to your custom view you want for cell background;