美文网首页
TableViewCell点击导致subviews背景颜色消失的

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

作者: knightyao | 来源:发表于2017-11-20 10:45 被阅读0次
//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背景颜色消失的

      本文链接:https://www.haomeiwen.com/subject/rfamvxtx.html