Created
July 2, 2019 06:05
-
-
Save prat14k/043c04b1844584a3e21439e918c5eff5 to your computer and use it in GitHub Desktop.
UITableView clearing the subview's background color on selection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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