I want to create cell with rounded corner radius and shadow. The problem is that my content view doesn’t clip to bounds and leave empty spaces in corners
class CollectionViewCell: UICollectionViewCell {
override func awakeFromNib() {
super.awakeFromNib()
setupView()
}
func setupView() {
self.contentView.layer.masksToBounds = true
self.contentView.clipsToBounds = true
self.layer.masksToBounds = false
self.layer.cornerRadius = 15
self.layer.borderWidth = 1
self.layer.borderColor = Colors.greenColor.cgColor
self.layer.shadowColor = UIColor.red.cgColor
self.layer.shadowRadius = 5
self.layer.shadowOpacity = 1.0
self.contentView.layer.shadowOffset = CGSize(width: 0, height: 0)
self.layer.shadowPath = UIBezierPath(rect: self.bounds).cgPath
}
I assume that the problem can be caused by code below, but I’ve changed values to 0 and it didn’t help.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
}
I will appreciate for indicators.
2
Answers
you can try adding an additional View container
this extension will help you in storyboard:)