繁体   English   中英

UITableView编辑时如何取消选中单元格高亮背景色

[英]How can I cancel the selected cell highlighted backgroundcolor when UITableView is editting

我设置单元格[cell.contentView addSubview:chatView] 。chatView 有一个UIImageView 、两个UILabels和 UILabel backgroundColor = [UIColor clearColor]

编辑表格时,我 select 单元格,单元格突出显示,UILabel backgroundColor 更改突出显示颜色。 我怎样才能取消backgroupColor。

theLabel.layer.backgroundColor = myColor

这很好用。

如果您只希望单元格 select 不突出显示,您可以这样做:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

我不确定您要取消 label BgColor 还是单元格

如果您不希望所选单元格更改其背景颜色,请将单元格的selectionStyle属性设置为UITableViewCellSelectionStyleNone即:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

标签的背景颜色设置为单元格突出显示颜色的原因是因为您已将标签的背景颜色属性设置为清除颜色。

如果这能解决您的问题,请告诉我。

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    if (self.editing) {

        for (UIView *view in self.contentView.subviews) {
            for (UIView *subview in view.subviews) {
                if ([subview isMemberOfClass:[UILabel class]]) {
                    subview.backgroundColor = [UIColor clearColor];
                }
            }

        }
    }
}

我将 UITableViewCell 子类化,并覆盖方法- (void)setSelected:(BOOL)selected animated:(BOOL)animated

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM