Skip to content

Instantly share code, notes, and snippets.

@wassim93
Last active August 23, 2021 02:31
Show Gist options
  • Save wassim93/91c1c50787570ec064c870c300fe0776 to your computer and use it in GitHub Desktop.
Save wassim93/91c1c50787570ec064c870c300fe0776 to your computer and use it in GitHub Desktop.
round corner only for top left-right
//Pay attention to the fact that if you have layout constraints attached to it, you must refresh this as follows in your UIView subclass:
override func layoutSubviews() {
super.layoutSubviews()
roundCorners(corners: [.topLeft, .topRight], radius: 3.0)
}
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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment