Last active
June 14, 2019 09:32
-
-
Save pgpt10/1004d03faedf191818417d0f5a34353a to your computer and use it in GitHub Desktop.
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
class CustomCollectionViewCell: UICollectionViewCell | |
{ | |
//Gradient to add in the cell | |
private lazy var gradient: CAGradientLayer = { | |
let gradientLayer = CAGradientLayer() | |
gradientLayer.colors = [UIColor.darkGray.cgColor, UIColor.orange.cgColor] | |
gradientLayer.startPoint = CGPoint(x: 0, y: 0) | |
gradientLayer.endPoint = CGPoint(x: 1, y: 1) | |
gradientLayer.frame = self.bounds | |
return gradientLayer | |
}() | |
//Handling adding and removing gradient as selection state changes | |
override var isSelected: Bool{ | |
didSet{ | |
if self.isSelected | |
{ | |
self.layer.insertSublayer(self.gradient, at: 0) | |
} | |
else | |
{ | |
self.gradient.removeFromSuperlayer() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment