UIView backgroundColor disappears when UITableViewCell is selected

前端 未结 17 1070
谎友^
谎友^ 2020-11-30 17:49

I have a simple tableViewCell build in interface builder. It contains a UIView which contains an image. Now, when I select the cell, the default blue selection background is

17条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 18:26

    Add this to your UITableViewCell

    override func setHighlighted(highlighted: Bool, animated: Bool) {
        super.setHighlighted(false, animated: animated)
        if highlighted {
            self.backgroundColor = UIColor.blueColor()
        }else{
            UIView.animateWithDuration(0.2, animations: {
                self.backgroundColor = UIColor.clearColor()
            })
        }
    }
    

提交回复
热议问题