iOS 处理cell选中时背景颜色消息问题

在cell上添加子控件,在我们点击或者长按的时候,如果子控件有背景颜色,这时候背景颜色就会没有了,这个时候产品经理过来一顿怼,😄。就想下面这个图:

 

那么想做到长按或者点击的时候背景颜色不被渲染,很简单,在自定cell上的时候写两个方法:

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    [self changColor];
    // Configure the view for the selected state
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    [super setHighlighted:highlighted animated:animated];
    [self changColor];
}

- (void)changColor
{
    //这里子控件初始化是什么颜色就设置什么颜色.
    self.label.backgroundColor = [UIColor orangeColor];
    
    //其他子控件的背景颜色
}

已经好了,run起来:

 

解决!

 

posted @ 2017-07-26 16:08  iOS_Doman  阅读(425)  评论(0编辑  收藏  举报