I want to trim it 50% but from top to bottom, so I want it trimmed from the center to the top.
Thanks for your reply. In fact, I expected some more info about all the views in your app, if there is any other views overlapping to your shape or how your shape is arranged in your app, etc... Sorry, my words are not enough.
So, assuming the simplest case, you may use clipShape.
Define your clipping rect, for example:
struct RectBand: Shape {
var from: CGFloat
var to: CGFloat
func path(in rect: CGRect) - Path {
Path { path in
path.addRect(CGRect(
x: rect.origin.x,
y: rect.origin.y + from * rect.size.height,
width: rect.size.width,
height: (to-from) * rect.size.height
))
}
}
}
And use it with clipShape like this:
Raindrop()
.clipShape(RectBand(from: 0.4, to: 0.9))
.scaledToFit()
Of course you may need to adjust the values from and to.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: