I've got a table view, how can I select a cell with different colour? Or how can I set the image of selection? thank开发者_运维问答s
You can easily change the cells selection style to gray:
[myTableView setSelectionStyle: UITableViewCellSelectionStyleGray];
Or you can change the contentView's
backgroundColor
in the willDisplayCell
delegate:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.backgroundColor = [UIColor redColor];
}
Another way would be to create a custom cell and change the color of the Background.
UIView *bgColorView = [[UIView alloc] init];
[bgColorView setBackgroundColor:[UIColor redColor]];
[cell setSelectedBackgroundView:bgColorView];
[bgColorView release];
Presumably you could do the same with a UIImageView as well
UIImageView *bgImageView = [[UIImageView imageNamed:@"Your Image"];
[cell setSelectedBackgroundView:bgImageView];
[bgImageView release];
精彩评论