Adding rounded corner and drop shadow to UICollectionViewCell

前端 未结 15 2639
逝去的感伤
逝去的感伤 2020-12-12 09:50

So I already went through various posts on adding 2nd view for adding shadow, but I still cannot get it to work if I want to add it in UICollectionViewCell. I s

15条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 10:51

    Here the Swift 4 solution, updated to round every corners and not only the top corners:

    contentView.layer.cornerRadius = 6.0
    contentView.layer.borderWidth = 1.0
    contentView.layer.borderColor = UIColor.clear.cgColor
    contentView.layer.masksToBounds = true
    
    layer.shadowColor = UIColor.lightGray.cgColor
    layer.shadowOffset = CGSize(width: 0, height: 2.0)
    layer.shadowRadius = 6.0
    layer.shadowOpacity = 1.0
    layer.masksToBounds = false
    layer.shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: contentView.layer.cornerRadius).cgPath
    layer.backgroundColor = UIColor.clear.cgColor
    

提交回复
热议问题