UITableViewCell在编辑状态下如何修改背景颜色

小编给大家分享一下UITableViewCell在编辑状态下如何修改背景颜色,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

渭滨ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:13518219792(备注:SSL证书合作)期待与您的合作!

一、先看下效果图

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,清除选中时候的灰色背景.

看完了这篇文章,相信你对“UITableViewCell在编辑状态下如何修改背景颜色”有了一定的了解,如果想了解更多相关知识,欢迎关注创新互联行业资讯频道,感谢各位的阅读!

网页标题:UITableViewCell在编辑状态下如何修改背景颜色
当前网址:https://www.cdcxhl.com/article36/jjoopg.html

成都网站建设公司_创新互联,为您提供网站制作外贸建站自适应网站定制开发软件开发网站维护

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都app开发公司