Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIBezierPath Subtract Path

By using [UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:], I am able to create a rounded view, such as this:

rounded view

How could I subtract another path from this one (or some other way), to create a path like this:

subtracted view

Is there any way I can do something like this? Pseudocode:

UIBezierPath *bigMaskPath = [UIBezierPath bezierPathWithRoundedRect:bigView.bounds                                   byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)                                        cornerRadii:CGSizeMake(18, 18)]; UIBezierPath *smallMaskPath = [UIBezierPath bezierPathWithRoundedRect:smalLView.bounds                                       byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)                                            cornerRadii:CGSizeMake(18, 18)];  UIBezierPath *finalPath = [UIBezierPath pathBySubtractingPath:smallMaskPath fromPath:bigMaskPath]; 
like image 315
jadengeller Avatar asked Jan 14 '12 01:01

jadengeller


1 Answers

Actually there is a much simpler way for most cases, example in Swift:

path.append(cutout.reversing()) 

This works because the default fill rule is the non-zero winding rule.

like image 63
Patrick Pijnappel Avatar answered Sep 23 '22 23:09

Patrick Pijnappel