Why do all backgrounds disappear on UITableViewCell select?

前端 未结 8 1911
南笙
南笙 2020-12-02 14:22

My current project\'s UITableViewCell behavior is baffling me. I have a fairly straightforward subclass of UITableViewCell. It adds a few extra elements to the base view (vi

8条回答
  •  感情败类
    2020-12-02 14:45

    My solution is saving the backgroundColor and restoring it after the super call.

    - (void)setSelected:(BOOL)selected animated:(BOOL)animated
    {
        UIColor *bgColor = self.textLabel.backgroundColor;
        [super setSelected:selected animated:animated];
        self.textLabel.backgroundColor = bgColor;
    }
    

    You also need to do the same thing with -setHighlighted:animated:.

提交回复
热议问题