I would like to stroke the path of a CAShapeLayer
with two alternating colours (black and white for example, think Preview.app selection boxes). I am not sure how to do this, or whether this is even possible with Quartz.
I have set up a CAShapeLayer to have a white border, and then set the path property to be a dashed black line. My hope was that this should give the effect of a black and white dashed lines. However, it seems that the path is drawn first the border is stroked on top, see screenshot (the fur belongs to my cat),
Can anybody suggest a better approach or a way to get this to work?
The code,
// Stroke a white border
[shapeLayer setFrame:shapeRect];
[shapeLayer setBorderColor:[[NSColor whiteColor] CGColor]];
[shapeLayer setBorderWidth:1.0];
// Stroked a black dash path (along the border)
// and fill shape with clear colour
[shapeLayer setFillColor:[[NSColor clearColor] CGColor]];
[shapeLayer setStrokeColor:[[NSColor blackColor] CGColor]];
[shapeLayer setLineWidth:1.0];
[shapeLayer setLineJoin:kCALineJoinRound];
[shapeLayer setLineDashPattern:
[NSArray arrayWithObjects:[NSNumber numberWithInt:5],
[NSNumber numberWithInt:5],
nil]];
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path, NULL, shapeLayer.bounds);
[shapeLayer setPath:path];
CGPathRelease(path);