Created
April 3, 2018 14:22
-
-
Save taktamur/94759b6330cef1e1f5f322626bb8ea65 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class SelectedCell:UITableViewCell { | |
override func setHighlighted(_ highlighted: Bool, animated: Bool) { | |
// ↓を呼び出すと、highlightedがfalseの場合に、 | |
// UITableViewCellSelectionStyleで指定した色(.grayとか)になるみたい。 | |
// super.setHighlighted(highlighted, animated: animated) | |
if( highlighted ) { | |
// こっちは指で押した時に呼び出される | |
// → 押しっぱなしにしていると赤が見える | |
self.contentView.backgroundColor = UIColor.red | |
}else{ | |
// 指を離した時に呼び出される | |
self.contentView.backgroundColor = UIColor.green | |
// 元の色に戻るようなアニメーションを仕込める | |
UIView.animate(withDuration: 0.5, animations: { | |
self.contentView.backgroundColor = UIColor.white | |
}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment