How to give shadow like card in iOS

后端 未结 5 1047
庸人自扰
庸人自扰 2020-12-13 05:49

I would like to give shadow effect like card similar to the image in my iOS app

I need this on UITableViewCell the image will not work for me also the the g

5条回答
  •  情话喂你
    2020-12-13 06:19

    An improvised solution on swift 3.0:

    extension UIView {
    
        func setCardView(){
            layer.cornerRadius = 5.0
            layer.borderColor  =  UIColor.clear.cgColor
            layer.borderWidth = 5.0
            layer.shadowOpacity = 0.5
            layer.shadowColor =  UIColor.lightGray.cgColor
            layer.shadowRadius = 5.0
            layer.shadowOffset = CGSize(width:5, height: 5)
            layer.masksToBounds = true
        }
    }
    

    Usage:

    On cellForRowAt indexPath:

    var cell = UITableViewCell()
    
    cell.contentView.setCardView()
    

提交回复
热议问题