Skip to content

Instantly share code, notes, and snippets.

@rafattouqir
Last active January 16, 2020 09:12
Show Gist options
  • Save rafattouqir/9e8576377ab2b66514bca9bbf471659c to your computer and use it in GitHub Desktop.
Save rafattouqir/9e8576377ab2b66514bca9bbf471659c to your computer and use it in GitHub Desktop.
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