Reputation: 19307
How to change the gray color when cell been selected?
Upvotes: 0
Views: 4275
Reputation: 759
When user click on Selected Row
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.contentView.backgroundColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];
}
Upvotes: 3
Reputation: 385
Try this :
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
Upvotes: 1
Reputation: 19307
Thanks @Kjuly and @Selkie's answer. I make it works with both of you.
selectedBackgroundView
's backgroundColor first.cell.textLabel.backgroundColor
and cell.contentView.backgroundColor
at didSelectedRowAtIndexPath
.Thank you again.
Upvotes: 1
Reputation: 35181
Set the selectedBackgroundView
's color as what you want in your custom tableview cell (which is a subclass of UITableViewCell):
UIView * selectedBackgroundView = [[UIView alloc] initWithFrame:self.frame];
[selectedBackgroundView setBackgroundColor:[UIColor redColor]]; // set color here
[self setSelectedBackgroundView:selectedBackgroundView];
[selectedBackgroundView release];
or you can configure it in -tableView:cellForRowAtIndexPath:
method:
//...
[cell setSelectedBackgroundView:selectedBackgroundView];
//...
Upvotes: 2
Reputation: 1783
How about change the background color in delegate method:
-(void)tableView:(UITableView *)tableView didSelectedRowAtIndexPath:(NSIndexPath *)indexPath
Upvotes: 1