Adding rounded corner and drop shadow to UICollectionViewCell

前端 未结 15 2647
逝去的感伤
逝去的感伤 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条回答
  •  萌比男神i
    2020-12-12 10:52

    SWIFT 4.2

    One should add this in your custom cell or cellForItemAt: If you are using the cellForItemAt: approach substitute self -> cell

            self.layer.cornerRadius = 10
            self.layer.borderWidth = 1.0
            self.layer.borderColor = UIColor.lightGray.cgColor
    
            self.layer.backgroundColor = UIColor.white.cgColor
            self.layer.shadowColor = UIColor.gray.cgColor
            self.layer.shadowOffset = CGSize(width: 2.0, height: 4.0)
            self.layer.shadowRadius = 2.0
            self.layer.shadowOpacity = 1.0
            self.layer.masksToBounds = false
    

    This will give you a cell with a rounded border and a drop shadow.

提交回复
热议问题