选择单元格时如何更改灰色?
问问题
4262 次
5 回答
3
当用户单击选定行时
(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];
}
于 2012-07-23T13:32:59.850 回答
2
在自定义表格视图单元格(UITableViewCell 的子类)中将 's 颜色设置selectedBackgroundView
为您想要的颜色:
UIView * selectedBackgroundView = [[UIView alloc] initWithFrame:self.frame];
[selectedBackgroundView setBackgroundColor:[UIColor redColor]]; // set color here
[self setSelectedBackgroundView:selectedBackgroundView];
[selectedBackgroundView release];
或者您可以在-tableView:cellForRowAtIndexPath:
方法中配置它:
//...
[cell setSelectedBackgroundView:selectedBackgroundView];
//...
于 2012-07-20T03:40:54.713 回答
1
如何在委托方法中更改背景颜色:
-(void)tableView:(UITableView *)tableView didSelectedRowAtIndexPath:(NSIndexPath *)indexPath
于 2012-07-20T03:36:53.477 回答
1
感谢@Kjuly 和@Selkie 的回答。我让它对你们俩都有效。
- 首先设置
selectedBackgroundView
的背景颜色。 - 改变
cell.textLabel.backgroundColor
和cell.contentView.backgroundColor
在didSelectedRowAtIndexPath
。
再次感谢你。
于 2012-07-20T03:52:22.490 回答
1
试试这个 :
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
于 2012-07-20T05:29:55.837 回答