如何改变UITableViewCellselect视图的颜色?
如何更改单元格被选中时的灰色颜色?
当用户点击选定的行
(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]; }
将selectedBackgroundView
的颜色设置为自定义tableview单元格(它是UITableViewCell的子类)中的所需颜色:
UIView * selectedBackgroundView = [[UIView alloc] initWithFrame:self.frame]; [selectedBackgroundView setBackgroundColor:[UIColor redColor]]; // set color here [self setSelectedBackgroundView:selectedBackgroundView]; [selectedBackgroundView release];
或者你可以在-tableView:cellForRowAtIndexPath:
configuration它-tableView:cellForRowAtIndexPath:
method:
//... [cell setSelectedBackgroundView:selectedBackgroundView]; //...
如何在委托方法中更改背景颜色:
-(void)tableView:(UITableView *)tableView didSelectedRowAtIndexPath:(NSIndexPath *)indexPath
谢谢@Kjuly和@ Selkie的回答。 我让它与你们两个一起工作。
- 首先设置
selectedBackgroundView
的backgroundColor。 - 在
didSelectedRowAtIndexPath
处更改cell.textLabel.backgroundColor
和cell.contentView.backgroundColor
。
再次感谢你。
尝试这个 :
cell.selectionStyle = UITableViewCellSelectionStyleBlue;