2
votes

So I have an UIView (called myView) with some mask applied to it.

let maskPath = UIBezierPath(roundedRect: myView.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 12, height: 12))
let maskLayer = CAShapeLayer()
maskLayer.frame = myView.bounds
maskLayer.path = maskPath.cgPath
myView.layer.mask = maskLayer

Which layout this way:

enter image description here

What I am failing to do is add some shadow to myView. Since the view's layer have a mask, I am not able to add differents layers to it with shadow.

Does anyone ever had this problem?

1

1 Answers

2
votes

set your image color to clear and to the following:

let maskPath = UIBezierPath(roundedRect: redView.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 12, height: 12))
        let maskLayer = CAShapeLayer()[![enter image description here][1]][1]
        maskLayer.fillColor = UIColor.red.cgColor // your color
        maskLayer.frame = redView.bounds
        maskLayer.path = maskPath.cgPath

        redView.layer.addSublayer(maskLayer)

        redView.layer.shadowOffset = CGSize(width: 10, height: 10)
        redView.layer.shadowColor = UIColor.green.cgColor
        redView.layer.shadowOpacity = 1