Created
April 26, 2021 17:20
-
-
Save marlonjames71/09d65599fb0cf94584bdace2f63d50cd to your computer and use it in GitHub Desktop.
Can specify which corners of a `UIView` are rounded. Extended `CACornerMask` OptionSet to be a bit more readable and friendlier to use.
This file contains hidden or 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 { | |
| /// Applies rounded corners with masking to specific corners and with corner curve option. | |
| func roundCorners(cornerRadius: CGFloat, roundedStyle: CALayerCornerCurve, corners: CACornerMask) { | |
| layer.cornerRadius = cornerRadius | |
| layer.cornerCurve = roundedStyle | |
| layer.maskedCorners = corners | |
| } | |
| } | |
| extension CACornerMask { | |
| /// Applies mask to all corners | |
| public static var allCorners: CACornerMask { | |
| [.layerMaxXMaxYCorner, .layerMinXMinYCorner, .layerMaxXMinYCorner, .layerMinXMaxYCorner] | |
| } | |
| /// Applies mask to top left and top right corners | |
| public static var topCorners: CACornerMask { | |
| [.layerMinXMinYCorner, .layerMaxXMinYCorner] | |
| } | |
| /// Applies mask to bottom left and bottom right corners | |
| public static var bottomCorners: CACornerMask { | |
| [.layerMinXMaxYCorner, .layerMaxXMaxYCorner] | |
| } | |
| /// Applies mask to top left and bottom left corners | |
| public static var leftCorners: CACornerMask { | |
| [.layerMinXMinYCorner, .layerMinXMaxYCorner] | |
| } | |
| /// Applies mask to top right and bottom right corners | |
| public static var rightCorners: CACornerMask { | |
| [.layerMaxXMinYCorner, .layerMaxXMaxYCorner] | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment