UICollectionView Cell Shadow

后端 未结 4 1177
长情又很酷
长情又很酷 2021-02-06 02:07

I am trying to add shadow to my custom UICollectionViewCell, This is the code I am using in my custom collection view cell class:

self.layer.shadowO         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-06 02:57

    Swift 4.2 and xcode 10

    here's code for adding a shadow.

        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.backgroundColor = UIColor.white.cgColor
        cell.layer.shadowColor = UIColor.gray.cgColor
        cell.layer.shadowOffset = CGSize(width: 0, height: 2.0)//CGSizeMake(0, 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
    

提交回复
热议问题