Iphone 如何更改UITableViewCell选定视图的颜色?
选择单元格后如何更改灰色Iphone 如何更改UITableViewCell选定视图的颜色?,iphone,ios,uitableview,Iphone,Ios,Uitableview,选择单元格后如何更改灰色 如何更改委托方法中的背景色: -(void)tableView:(UITableView *)tableView didSelectedRowAtIndexPath:(NSIndexPath *)indexPath 将所选背景视图的颜色设置为自定义tableview单元格(UITableViewCell的子类)中所需的颜色: 或者您可以在-tableView:cellforrowatinexpath:方法中配置它: //... [cell setSelectedBac
如何更改委托方法中的背景色:
-(void)tableView:(UITableView *)tableView didSelectedRowAtIndexPath:(NSIndexPath *)indexPath
将所选背景视图的颜色设置为自定义tableview单元格(UITableViewCell的子类)中所需的颜色: 或者您可以在
-tableView:cellforrowatinexpath:
方法中配置它:
//...
[cell setSelectedBackgroundView:selectedBackgroundView];
//...
谢谢@Kjuly和@Selkie的回答。我让它和你们两个一起工作
cell.textLabel.backgroundColor
和cell.contentView.backgroundColor
atdidSelectedRowAtIndexPath
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
当用户单击所选行时
(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];
}
在我看来,选项2虽然有效,但不是很好的解决方法。当它被选中时,它总是会改变单元格的正常背景色,当它被取消选中时,它需要再次设置为正常!
(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];
}