I have the below extension that allows me to round specific corners of a view:
extension CALayer {
func roundCorners(corners: UIRectCorner, radius: CGFloat, viewBounds: CGRect) {
let maskPath = UIBezierPath(roundedRect: viewBounds,
byRoundingCorners: corners,
cornerRadii: CGSize(width: radius, height: radius))
let shape = CAShapeLayer()
shape.path = maskPath.cgPath
mask = shape
}
}
Which is then used like:
innerView.layer.roundCorners(corners: [.bottomLeft, .bottomRight], radius: 20, viewBounds: innerView.bounds)
And works perfectly.
However if I then also want to add a shadow to that view the shadow isn't drawn, so for example:
override func viewDidAppear(_ animated: Bool) {
...
innerView.layer.roundCorners(corners: [.bottomLeft, .bottomRight], radius: 20, viewBounds: innerView.bounds)
innerView.layer.shadowColor = UIColor.gray.cgColor
innerView.layer.shadowOpacity = 0.7
innerView.layer.shadowOffset = CGSize(width: 1.0, height: 1.0)
innerView.layer.shadowRadius = 2
...
}
Results in the view just having the corners rounded but no shadow. How to do I create both the required shadow and be able to round specific corners (not just all 4 corners at once)