1

This is not asking the same question as How can I combine UIBezierPath drawings? even though the name is similar


I have a shape that needs to be able to scale vertically and on one side of it are rounded corners and the other side is some other path. I have drawn the following image to show what I am talking about, but this is not the exact shape I am making, but conceptually it is the same idea.

sample image

In this image, the left side is half of a rounded rectangle and the right side is half of a circle.

So I am wanting to take and essentially cut a rounded rectangle in half and basically "merge" it with another path. How can I do this?

I guess one way would be to have two layers: the top layer contains the shape on the right and the bottom layer contains the rounded rectangle, and the top layer occludes half of the rectangle. But I was hoping to not have to use two different layers, and instead be able to put all of this in one layer, so I was wondering if it was possible to merge the shapes like I mentioned.

ashipma
  • 423
  • 5
  • 15
  • 1
    Do you need the resulting `UIBezierPath`? Or, do you just need the "visual" shape? – DonMag Feb 08 '22 at 18:00
  • @DonMag I mostly just need the shape I guess. I ended up just creating a bezier path that is a rounded rectangle with the top left and bottom left corners rounded then I created another path that was my other shape, and I just appended those paths together and that worked. Basically what I am trying to do is have a view that has a background layer that is this shape. Inside this view I then have a label and the shape is supposed to match the size of the label. – ashipma Feb 09 '22 at 16:24
  • There are various ways to do this. If you just want the "visual result" you can do it the way you found works, or you can create the path with `.addLine(...)` / `.addArc(..)` / `.addCurve(...)` / `.addQuadCurve(...)` / etc. Or you can override `draw()` and stroke / fill as needed. Tough to offer good options, though, without details about what you're really trying to do -- especially when you say *"this is not the exact shape I am making"*. – DonMag Feb 09 '22 at 16:46

0 Answers0