Hello
I have a Raindrop shape:
When I trim it in the ContentView, it trims from right to left, is there a way to trim it from top to bottom?
Thank you
I have a Raindrop shape:
Code Block struct Raindrop: Shape { func path(in rect: CGRect) -> Path { Path { path in path.move(to: CGPoint(x: rect.size.width / 2, y: 0)) path.addQuadCurve(to: CGPoint(x: rect.size.width / 2, y: rect.size.height), control: CGPoint(x: rect.size.width, y: rect.size.height)) path.addQuadCurve(to: CGPoint(x: rect.size.width / 2, y: 0), control: CGPoint(x: 0, y: rect.size.height)) } } }
When I trim it in the ContentView, it trims from right to left, is there a way to trim it from top to bottom?
Code Block Raindrop() .trim(from: 0.9, to: 1) .scaledToFit()
Thank you
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.I want to trim it 50% but from top to bottom, so I want it trimmed from the center to the top.
So, assuming the simplest case, you may use clipShape.
Define your clipping rect, for example:
Code Block 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:
Code Block Raindrop() .clipShape(RectBand(from: 0.4, to: 0.9)) .scaledToFit()
Of course you may need to adjust the values from and to.