How to change color of UITableViewCell when selecting?

前端 未结 14 2508
予麋鹿
予麋鹿 2020-12-04 10:59

I have a menu like so:

\"Menu\"

The normal (unselected) state for each cell is an image, the selected s

14条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 11:18

    Easier than accepted answer:

    In your UITableViewCell subclass:

    In awakeFromNib or init:

    self.selectionStyle = UITableViewCellSelectionStyleNone;

    Then:

    - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
    {
        [super setHighlighted:highlighted animated:animated];
    
        if (highlighted) {
            self.backgroundColor = [UIColor yourHighlightColor];
        }
        else {
            self.backgroundColor = [UIColor yourNormalColor];
        }
    }
    

提交回复
热议问题