I have followed: https://stackoverflow.com/a/25493235 and https://stackoverflow.com/a/44820559 but I cannot get my cells to be rounded without doing cell.layer.cornerRadius = X
instead of cell.contentView.layer.cornerRadius = X
Here is my code for the function that defines my cell in the collectionView:
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath as IndexPath) as! CustomCollectionCell
cell.backgroundColor = UIColor.white
cell.contentView.layer.cornerRadius = 2.0
cell.contentView.layer.borderWidth = 1.0
cell.contentView.layer.borderColor = UIColor.clear.cgColor
cell.contentView.layer.masksToBounds = true
cell.layer.shadowColor = UIColor.lightGray.cgColor
cell.layer.shadowOffset = CGSize(width: 0, height: 2.0)
cell.layer.shadowRadius = 2.0
cell.layer.shadowOpacity = 1.0
cell.layer.masksToBounds = false
cell.layer.shadowPath = UIBezierPath(roundedRect: cell.bounds, cornerRadius: cell.contentView.layer.cornerRadius).cgPath
return cell
}
Prior to attempting to round the cells, all I had was cell.backgroundColor = UIColor.white
in that function, thus, all I have now is just the code from StackOverflow because I wanted to test it out. Any help would be appreciated.
It looks like this right now:
And this it looks like this with Pratik's suggestion:
Update:
I guess there's no other way to do it than:
- Make the cell.backgroundColor clear and make the contentView white
or
- Make the don't include a background color for the cell and just make the contentView white.