作者:周佳君7284 | 来源:互联网 | 2022-01-15 07:38
这篇文章主要给大家介绍了关于UITableViewCell在编辑状态下背景颜色的修改方法,文中通过示例代码介绍的非常详细,对大家具有一定的参考学习价值,需要的朋友们下面跟着小编一起来学习学习吧。
本文主要介绍的是关于UITableViewCell在编辑状态下背景颜色的修改方法,分享出来供大家参考学习,下面来一起看看详细的介绍:
一、先看下效果图
二、网上很多下面这种答案
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
cell.selectiOnStyle= UITableViewCellSelectionStyleNone;
这样设置,蓝色的选中图标也不会出现.
这种仅限于不编辑的时候,让TableViewCell没有灰色高亮.
三、具体实现:
(1).在创建cell的时候设置selectedBackgroundView
RealTimeControlTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil) {
cell = [[RealTimeControlTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
cell.contentView.backgroundColor = [UIColor clearColor];
UIView *backGroundView = [[UIView alloc]init];
backGroundView.backgroundColor = [UIColor clearColor];
cell.selectedBackgroundView = backGroundView;
}
(2).自定义一个UITableVIewCell重写
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
if (!self.editing) {
return;
}
[super setSelected:selected animated:animated];
if (self.editing) {
self.contentView.backgroundColor = [UIColor clearColor];
self.textLabel.backgroundColor = [UIColor clearColor];
self.detailTextLabel.backgroundColor = [UIColor clearColor];
}
}
(3)还要重写下面方法 因为在长按cell的时候也会高亮,出现灰色的背景
-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
return;
}
对上面第二步代码说明:
1.在非编辑状态下,默认不会出现选中效果,直接return.
return 以后还是会继续调用
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
在这里处理cell的点击事件
}
2.要实现选中的蓝色图标出现,以及添加cell到选中cell的数组.
调用系统的默认方法
[super setSelected:selected animated:animated];
3.在编辑状态下修改cell的contenView为clear,清除选中时候的灰色背景.
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如有疑问大家可以留言交流,谢谢大家对的支持。