源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

UITableViewCell在编辑状态下背景颜色的修改方法

  • 时间:2022-07-29 02:46 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:UITableViewCell在编辑状态下背景颜色的修改方法
本文主要介绍的是关于UITableViewCell在编辑状态下背景颜色的修改方法,分享出来供大家参考学习,下面来一起看看详细的介绍: [b]一、先看下效果图[/b] [img]http://files.jb51.net/file_images/article/201707/201772162126224.png?201762162133[/img] [b]二、网上很多下面这种答案[/b]
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
这样设置,蓝色的选中图标也不会出现. 这种仅限于不编辑的时候,让TableViewCell没有灰色高亮. [b]三、具体实现:[/b] (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;
}
[b]对上面第二步代码说明:[/b] 1.在非编辑状态下,默认不会出现选中效果,直接return. return 以后还是会继续调用
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
 在这里处理cell的点击事件
}
2.要实现选中的蓝色图标出现,以及添加cell到选中cell的数组. 调用系统的默认方法
[super setSelected:selected animated:animated];
3.在编辑状态下修改cell的contenView为clear,清除选中时候的灰色背景. [b]总结[/b] 以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如有疑问大家可以留言交流,谢谢大家对编程素材网的支持。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部