Created
January 30, 2021 18:32
-
-
Save cafielo/71e9f5ca352b0b2dc06498ab07c8af7e to your computer and use it in GitHub Desktop.
How to round only specific corners
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 { | |
func roundCorners(corners: UIRectCorner, radius: CGFloat) { | |
let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius)) | |
let mask = CAShapeLayer() | |
mask.path = path.cgPath | |
layer.mask = mask | |
} | |
} | |
let redBox = UIView(frame: CGRect(x: 100, y: 100, width: 128, height: 128)) | |
redBox.roundCorners(corners: [.topLeft, .topRight], radius: 3.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment