Reputation: 16051
I originally had this code, to create a 'bottom highlight' on buttons:
CGContextAddPath(context, highlightPath);
CGContextSetFillColorWithColor(context, [[UIColor colorWithWhite:1.0 alpha:0.5]CGColor]);
CGContextFillPath(context);
This would draw the highlight in the same space as the button, but 1 pixel lower, and this worked fine, as the buttons weren't transparent. I now have some transparent ones, however, so I need to remove the area behind the button from the drawing area.
I've tried using EOClip
to do this, but wasn't able to figure out which combination to use. The button's path is called buttonPath
, the highlight path is the same but 1 pixel lower, and called highlightPath
. How could i stop it from drawing inside buttonPath
, while drawing to highlightPath?
EDIT:
Ok, so both this and switching lines 2 and 3 result in the whole shape being colored, and an error of clip: empty path.
:
CGContextEOClip(context);
CGContextAddPath(context, buttonPath);
CGContextAddPath(context, highlightPath);
CGContextSetFillColorWithColor(context, [[UIColor colorWithWhite:1.0 alpha:0.5] CGColor]);
CGContextFillPath(context);
Upvotes: 0
Views: 780
Reputation: 56625
As concluded from the chat, you can add both paths and fill with an even-odd fill mode to get the desired result
CGContextAddPath(context, buttonPath);
CGContextAddPath(context, highlightPath);
CGContextSetFillColorWithColor(context, [[UIColor colorWithWhite:1.0 alpha:0.5] CGColor]);
CGContextEOFillPath(context);
Upvotes: 1