Skip to content

Instantly share code, notes, and snippets.

@sukidhar
Created August 15, 2020 14:59
Show Gist options
  • Save sukidhar/e7f92ca0db783c17c85946c321241ef3 to your computer and use it in GitHub Desktop.
Save sukidhar/e7f92ca0db783c17c85946c321241ef3 to your computer and use it in GitHub Desktop.
extension View {
func cornerRadius(_ radius: CGFloat, corners: UIRectCorner) -> some View {
clipShape( RoundedCorner(radius: radius, corners: corners) )
}
}
struct RoundedCorner: Shape {
var radius: CGFloat = .infinity
var corners: UIRectCorner = .allCorners
func path(in rect: CGRect) -> Path {
let path = UIBezierPath(roundedRect: rect, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
return Path(path.cgPath)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment