Skip to content

Instantly share code, notes, and snippets.

@cafielo
Created January 30, 2021 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cafielo/71e9f5ca352b0b2dc06498ab07c8af7e to your computer and use it in GitHub Desktop.
Save cafielo/71e9f5ca352b0b2dc06498ab07c8af7e to your computer and use it in GitHub Desktop.
How to round only specific corners
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