Last active
January 16, 2020 09:12
-
-
Save rafattouqir/9e8576377ab2b66514bca9bbf471659c 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
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | |
let cell: CustomCollectionViewCell = collectionView.dequeueReusableCell(forIndexPath: indexPath) | |
... | |
//add shadow | |
cell.applyShadow() | |
.... | |
return cell | |
} | |
extension UICollectionViewCell{ | |
func applyShadow(cornerRadius: CGFloat = 8, shadowColor: UIColor = UIColor.black.withAlphaComponent(0.6 ), shadowOffset: CGSize = .zero, shadowRadius: CGFloat = 4){ | |
let cell = self | |
cell.contentView.layer.masksToBounds = true//mask contentview layer | |
cell.layer.cornerRadius = cornerRadius | |
cell.layer.borderWidth = 0.0 | |
cell.layer.shadowColor = shadowColor.cgColor | |
cell.layer.shadowOffset = shadowOffset | |
cell.layer.shadowRadius = shadowRadius | |
cell.layer.shadowOpacity = 1 | |
cell.layer.masksToBounds = false //main thing is to unmask cell layer | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment