TableViewCell点击导致subviews背景颜色消失的处理

//MARK: - 重写高亮和点击事件
    override func setHighlighted(highlighted: Bool, animated: Bool) {
        var colors: [UIView:UIColor] = [:]
        for view in subviews {
            colors[view] = view.backgroundColor ?? UIColor.clearColor()
        }
        super.setHighlighted(highlighted, animated: animated)
        if highlighted {
            for view in subviews {
                view.backgroundColor = colors[view]
            }
        }
    }
    override func setSelected(selected: Bool, animated: Bool) {
        var colors: [UIView:UIColor] = [:]
        for view in subviews {
            colors[view] = view.backgroundColor ?? UIColor.clearColor()
        }
        super.setSelected(selected, animated: animated)
        if selected {
            for view in subviews {
                view.backgroundColor = colors[view]
            }
        }
    }

你可能感兴趣的:(TableViewCell点击导致subviews背景颜色消失的处理)