I have a custom UIButton. I want to add radius to some corners (not to all of them) I'm using UIBezierPath for setting that. But because i'm masking the layer i cant add a shadow.
For all corners it works:
func setupView() {
layer.cornerRadius = 10
addShadow(UIColor.blackColor(), opacity: 0.8, radius: 5, offset: CGSizeMake(1, 1))
}
func addShadow(color: UIColor, opacity: Float, radius: CGFloat, offset: CGSize){
layer.shadowColor = color.CGColor
layer.shadowOpacity = opacity
layer.shadowRadius = radius
layer.shadowOffset = offset
}
For some corners using UIBezierPath i get only the rounded corners but no shadow
func setupView() {
addCornerRadiusToCurners(false, leftTop: true, rightBottom: false, leftBottom: false, radius: 10)
addShadow(UIColor.blackColor(), opacity: 0.8, radius: 5, offset: CGSizeMake(1, 1))
}
func addCornerRadiusToCurners(rightTop: Bool = true, leftTop: Bool = true, rightBottom: Bool = true, leftBottom: Bool = true, radius: CGFloat) {
var corners: UIRectCorner = []
if rightTop { corners.insert(.TopRight) }
if leftTop { corners.insert(.TopLeft) }
if rightBottom { corners.insert(.BottomRight) }
if leftBottom { corners.insert(.BottomLeft) }
let cornerPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSizeMake(radius, radius))
let cornerMaskLayer = CAShapeLayer()
cornerMaskLayer.path = cornerPath.CGPath
layer.mask = cornerMaskLayer
}