Last active
October 6, 2016 02:24
-
-
Save edenman/80566f51fb5861fdea6d76e02e0b4e07 to your computer and use it in GitHub Desktop.
Swift (2.3) CALayer extension to only round _some_ corners
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CALayer { | |
func roundCorners(corners: UIRectCorner, radius: CGFloat) { | |
let maskPath = UIBezierPath(roundedRect: bounds, | |
byRoundingCorners: corners, | |
cornerRadii: CGSize(width: radius, height: radius)) | |
let shape = CAShapeLayer() | |
shape.path = maskPath.CGPath | |
mask = shape | |
} | |
} | |
// Usage: | |
myView.layer.roundCorners([.TopLeft, .TopRight], radius: myCornerRadius) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment