Light about a solution to draw cell rectangles
How to customize the background/border colors of a grouped table view cell?
After reading this post, i tried to use this solution. Here is my code, in the tableViewDelegate methods:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
CustomCellBackgroundView *customBac开发者_如何转开发kground = [CustomCellBackgroundView alloc];
[customBackground setBorderColor:[UIColor blackColor]];
[customBackground setFillColor:[UIColor redColor]];
[customBackground setPosition:0]; //i'll deal with that later
[cell setSelectedBackgroundView:customBackground];
[customBackground release];
UIImageView* selectedBackgroundCell = [[[UIImageView alloc] initWithFrame:CGRectNull] autorelease];
[selectedBackgroundCell setImage:[UIImage imageNamed:@"cell_bg_50_hover.png"]];
[customBackground drawRect:selectedBackgroundCell.frame];
[cell setSelectedBackgroundView:selectedBackgroundCell];
//standard background color
[cell setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_bg_50.png"]]];
}
But unfortunately it doesn't change anything. Do you know what I am doing wrong ?
I believe that whenever make views then you should specify some frame for that. So specify frame CGRectZero for both custom background and background....
Following just work for me when I tested.
UIView *bkview = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
bkview.backgroundColor = [UIColor redColor];
cell.selectedBackgroundView = bkview;
You release customBackground and then you call [customBackground drawRect:selectedBackgroundCell.frame];
So obviously, calling the function on a nil pointer won't do anything.
精彩评论