Question

As the title says, setLineDash applied to my NSBezierPath doesn't change the stroked line. No effect at all.

I expect it to make my line dashed. See two vertical red lines on the picture.

Code:

NSBezierPath* p= [NSBezierPath bezierPath];
CGFloat x = r.origin.x + r.size.width/2;

float dash_pattern[]={15.,15.};
NSInteger count = sizeof(dash_pattern)/sizeof(dash_pattern[0]);
[p setLineDash:(CGFloat*)dash_pattern count:count phase:0.]; // no effect ?

[p moveToPoint:NSMakePoint(x, r.origin.y+r.size.height)];
[p lineToPoint:NSMakePoint(x, [view bounds].origin.y+[view bounds].size.height)];
[[NSColor redColor]set];

[p stroke];

enter image description here

Was it helpful?

Solution

This is a shot in the dark, but on 64-bit OS X, CGFloat is a double and not a float. You should therefore define the array as

CGFloat dash_pattern[]={15.,15.};

This also makes the explicit cast in setLineDash:(CGFloat*)dash_pattern unnecessary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top