Skip to content

Instantly share code, notes, and snippets.

@prat14k
Created July 2, 2019 06:05
Show Gist options
  • Save prat14k/043c04b1844584a3e21439e918c5eff5 to your computer and use it in GitHub Desktop.
Save prat14k/043c04b1844584a3e21439e918c5eff5 to your computer and use it in GitHub Desktop.
UITableView clearing the subview's background color on selection
// UITableViewCell changes the background color of all sub views when cell is selected or highlighted.
// You can Solve this problem by overriding Tableview cell's setSelected:animated and setHighlighted:animated and resetting view background color.
// In Swift 3.1 :
override func setSelected(_ selected: Bool, animated: Bool) {
let color = yourView.backgroundColor
super.setSelected(selected, animated: animated)
if selected {
yourView.backgroundColor = color
}
}
override func setHighlighted(_ highlighted: Bool, animated: Bool) {
let color = yourView.backgroundColor
super.setHighlighted(highlighted, animated: animated)
if highlighted {
yourView.backgroundColor = color
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment