您好,欢迎来到二三娱乐。
搜索
您的当前位置:首页iOS tableView编辑状态取消选中的背景颜色

iOS tableView编辑状态取消选中的背景颜色

来源:二三娱乐

事情的起因呢,是因为在选中的时候cell里面的控件颜色改变了,然后测试提的bug就是,和设计图不符???


image.png

好吧,那我能怎么办呢,当然是改啊!
然后试过了很多办法,类似:

1、cell.selectionStyle = UITableViewCellSelectionStyleNone;
2、[tableView deselectRowAtIndexPath:indexPath animated:YES]; 
3、cell.selectedBackgroundView = [[UIView alloc] init];
4、在layoutSubviews方法中再次设置控件的背景颜色

你们猜怎么样?当然就是全部失败了(无奈脸)

第1,2种方法设置了之后,tableview编辑状态下就是这样的


1,2.png

看见了吗,前面的圆圈圈点了没反应了~~~~~

第3,4种方法设置了之后,tableview编辑状态下就是这样的


3,4.png

只有前面这一点点变了,后面依旧怎样还是怎样,好吧,你傲娇,我不跟你一般见识,就继续往下找方法吧。然后我牺牲了我的午休时间,终于把这个烦人的东西给干掉了,谁也不知道会这么简单,就两句代码就搞定了,你猜猜是什么,算了,你如果知道也不会上网搜了不是。。hhhh

分为两步,首先,初始化cell的地方

- (UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.tintColor = kBLRed;
cell.selectedBackgroundView = [[UIView alloc] init];
//就这两句代码
cell.multipleSelectionBackgroundView = [[UIView alloc] initWithFrame:cell.bounds];
cell.multipleSelectionBackgroundView.backgroundColor = [UIColor clearColor];

return cell;
}

然后在自定义cell里面的

-(void)setSelected:(BOOL)selected animated:(BOOL)animated

方法里面重写控件的颜色就可以了然后就会实现你想实现的效果了

image.png

api (多选情况下被选中时的背景view)

multipleSelectionBackgroundView:If not nil, takes the place of the selectedBackgroundViewwhen using multiple selection.

能怎么办呢~ 必须要记下来

本文如未解决您的问题请添加抖音号:51dongshi(抖音搜索懂视),直接咨询即可。

热门图文

Copyright © 2019-2025 yule263.com 版权所有 湘ICP备2023023988号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务