Skip to content

Instantly share code, notes, and snippets.

@comcxx11
Last active May 22, 2023 11:23
Show Gist options
  • Save comcxx11/169ff7c15528d91b4c1b14d48dbe726d to your computer and use it in GitHub Desktop.
Save comcxx11/169ff7c15528d91b4c1b14d48dbe726d to your computer and use it in GitHub Desktop.
20230522
box.layer.cornerRadius = 20;
box.layer.masksToBounds = true;
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
}
}
box.roundCorners(corners: [.topLeft, .topRight], radius: 20.0)
box.roundCorners(corners: [.topLeft, .bottomRight], radius: 20.0)
box.roundCorners(corners: [.bottomLeft, .bottomRight], radius: 20.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment