Search code examples
iosswiftcore-graphicsuibezierpathmasking

Using the existing paths to create a mask to a UIView?


I have a UIButton inside of which I draw three UIBezierPaths so that they create a triangle. Now, I need to fill the area of that triangle, but I don't know how to get that region. Using setFill (and then, fill) on the paths doesn't work.

Maybe, it is possible to achieve this by masking the view. If it is the case, I wonder how to achieve that (to create a triangular mask) by using existing paths (which, again, are set so that they create a triangular).

How can I fill the area between the three paths? If you know how to do that, I would appreciate your help.


Solution

  • How about instantiating a new UIView and using the path you just drew as a clipping mask? Then add the newly clipped object as a subview to your UIButton.