Last active
August 23, 2021 02:31
-
-
Save wassim93/91c1c50787570ec064c870c300fe0776 to your computer and use it in GitHub Desktop.
round corner only for top left-right
This file contains 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
//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