您的位置:首页 > 产品设计 > UI/UE

UITableViewCell 自定义点击状态时背景颜色

2015-12-10 15:03 169 查看
今天做一个需求,类似这个样子



tableViewCell点击时背景颜色不是系统默认的那两种(蓝,灰)。

卡了将近一个小时左右。上网找帖子,发现很多帖子都是选中时改变背景颜色,再点击下一个cell之前的那个cell颜色并不变回来 点了一圈 所有的cell就都成点击的颜色了。后来解决了之后发现 其实蛮简单的。

上代码:

// cell点击时
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == _sortTableView) {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.backgroundColor = RGB(1, 174, 159, 1.0);
}
}


然后当取消点击状态时

// 当cell取消选中状态时
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == _sortTableView) {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.backgroundColor = [UIColor whiteColor];
}
}


就这样就好啦。 哎,其实蛮简单的一个问题,不知道为什么 没人详细的解释一下。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: