iOS开发知识小集iOS (oc)

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

2018-05-19  本文已影响160人  红太狼的小灰帽丶

事情的起因呢,是因为在选中的时候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.

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

上一篇 下一篇

猜你喜欢

热点阅读