Skip to content

Instantly share code, notes, and snippets.

@edenman
Last active October 6, 2016 02:24
Show Gist options
  • Save edenman/80566f51fb5861fdea6d76e02e0b4e07 to your computer and use it in GitHub Desktop.
Save edenman/80566f51fb5861fdea6d76e02e0b4e07 to your computer and use it in GitHub Desktop.
Swift (2.3) CALayer extension to only round _some_ corners
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