UIView backgroundColor disappears when UITableViewCell is selected

前端 未结 17 1103
谎友^
谎友^ 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:32

    Swift 4

    In your UITableViewCell class:

    override func setSelected(_ selected: Bool, animated: Bool) {
        myView.backgroundColor = UIColor.blue
    }
    
    override func setHighlighted(_ highlighted: Bool, animated: Bool) {
        myView.backgroundColor = UIColor.blue
    }
    

提交回复
热议问题