Last active
February 21, 2018 08:48
-
-
Save vkostechko/11df0378617de3060b580660ba2546c5 to your computer and use it in GitHub Desktop.
UIView extension to round corners (https://stackoverflow.com/questions/10167266/how-to-set-cornerradius-for-only-top-left-and-top-right-corner-of-a-uiview/18376784)
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 UIView { | |
func roundCorners(_ corners: UIRectCorner, radius: CGFloat) { | |
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius)) | |
let mask = CAShapeLayer() | |
mask.path = path.cgPath | |
self.layer.mask = mask | |
} | |
} | |
usage: | |
view.roundCorners([.topLeft, .bottomRight], radius: 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment