UIView Round Corners with Shadow

前端 未结 3 1826
误落风尘
误落风尘 2020-12-31 05:22

I am trying to display a UIView with round corners and with a drop shadow. But the problem is that maskToBounds property only works for either of the case.

If maskT

3条回答
  •  我在风中等你
    2020-12-31 05:25

    You can do it with a single view by applying following:

    1. Firstly add a corner radius

    yourview.layer.cornerRadius = 5.0
    

    2. Call a function below

    shadowToView(view : yourview)
    
    
    func shadowToView(view : UIView){
        view.layer.shadowOffset = CGSize(width: 0, height: 3)
        view.layer.shadowOpacity = 0.6
        view.layer.shadowRadius = 3.0
        view.layer.shadowColor = UIColor.darkGray.cgColor
    }
    

提交回复
热议问题