zakhej zakhej - 2 months ago 27
iOS Question

Fill UIBezierPath

I'm try to dynamically create puzzle piece, and it looks like this:

not filled puzzle piece

I want to fill this shape with some color so it will looks like this:

filled puzzle piece

so I can use it for masking some image.

I creating this shape with 4 UIBezierPath, then convert it to 1 path using


I want to fill this path but when I use
I got this:

bad filled puzzle piece

Do you have any ideas how I can fill same shapes?


After some time I found a reason why I got these results. If you want to create some path for filling you should not use moveToPoint method, instead you should just once set first point using moveToPoint and then draw all lines with addLineToPoint, addCurveToPoint, etc.

After you complete draw your path do not forget send closePath message.

Before I knew this, I drew every side of puzzle piece using different UIBezierPath instances and for every path I set first point using moveToPoint.