I have a view that I want to apply a clipShape
modifier to a rounded rectangle that has only the top left and bottom left rounded corners.
I am using this extension to round specific corners of some views I have.
So, I would love if I could do this:
.clipShape(Rectangle().cornerRadius(20, [.topLeft, .topRight]))
But I got error saying Rectangle must be a shape...
So I suppose I have to create something like:
struct RectangleX: Shape {
func path(in rect: CGRect) -> Path {
var radius = CGFloat.infinity
var corners = UIRectCorner.allCorners
let path = UIBezierPath(roundedRect: rect,
byRoundingCorners: corners,
cornerRadii: CGSize(width: radius,
height: radius))
return Path(path.cgPath)
}
}
but I am failing to see how do I pass the rect to this.