Search code examples
ios7xcode5quartz-2d

IOS quartz 2d Line Joins and Diamond shapes


I'm working on a simple drawing app for ios. The line join doesn't seem to be working for the top (north) point of the diamond.

Example

Here is the code:

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, _currentSize);
CGContextSetStrokeColorWithColor(context, _currentColor.CGColor);
CGContextSetLineJoin(context, kCGLineJoinRound);

CGContextMoveToPoint(context, _firstTouch.x, _firstTouch.y);
CGContextAddLineToPoint(context, _firstTouch.x + delta, _firstTouch.y + delta);
CGContextAddLineToPoint(context, _firstTouch.x, _firstTouch.y + (2*delta));
CGContextAddLineToPoint(context, _firstTouch.x - delta, _firstTouch.y + delta);
CGContextAddLineToPoint(context, _firstTouch.x, _firstTouch.y);
CGContextDrawPath(context, kCGPathFillStroke);

delta simply represents the length of the sides.

The LineJoin property is working on all points except for the north point (where the path starts and ends.

Any guidance would be appreciated.


Solution

  • You forgot to close the path. Close it.

    https://developer.apple.com/library/mac/documentation/graphicsimaging/reference/CGContext/Reference/reference.html#//apple_ref/c/func/CGContextClosePath