TableViewCell点击导致subviews背景颜色消失的
2017-11-20 本文已影响0人
knightyao
//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]
}
}
}