Why do all backgrounds disappear on UITableViewCell select?

前端 未结 8 1898
南笙
南笙 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 15:11

    Found a pretty elegant solution instead of messing with the tableView methods. You can create a subclass of UIView that ignores setting its background color to clear color. Code:

    class NeverClearView: UIView {
        override var backgroundColor: UIColor? {
            didSet {
                if UIColor.clearColor().isEqual(backgroundColor) {
                    backgroundColor = oldValue
                }
            }
        }
    }
    

    Obj-C version would be similar, the main thing here is the idea

提交回复
热议问题