CGContextSetStrokeColorWithColor only changes the state of the context, it does not make any drawing. The only drawing made in your code is the CGContextStrokePath at the end. Because each call to CGContextSetStrokeColorWithColor overrides the value set by the previous call, the drawing will use the last color set.
You need to create a new path, set the color and then draw in each loop. Something like that:
for(int idx = 0; idx < routeGrabInstance.points.count; idx++) { CGContextBeginPath(ctx); CGContextMoveToPoint(ctx, x1, y1); CGContextAddLineToPoint(ctx, x2, y2); CGContextSetStrokeColorWithColor(ctx,tempColor.CGColor); CGContextStrokePath(ctx); }
source share