draw a multicolor line with a CGPath <p>below you see a code that draws a multicolor line each time drawMulticolorLine is called.</p> <pre><code> void drawMulticolorLine { CGContextBeginPath(secondaryContext); CGContextMoveToPoint(secondaryContext, h, v); for( int i = 1; i &lt; lineWidth; ++ ) { SetStrokeColor(i); CGContextAddLineToPoint(secondaryContext, h+i, v); CGContextDrawPath(secondaryContext, kCGPathFillStroke); CGContextMoveToPoint(secondaryContext, h+i, v); } } //a function that sets a different color for each i void SetStrokeColor(int i) { CGContextSetRGBStrokeColor(secondaryContext,… } </code></pre> <p>the code above works but if i use it in real live, it is a perfomance killer. so i try to improve the drawing performance with the code below.</p> <pre><code> void drawMulticolorLine { CGContextBeginPath(secondaryContext); CGContextMoveToPoint(secondaryContext, h, v); for( int i = 1; i &lt; lineWidth; ++ ) { SetStrokeColor(i); CGContextAddLineToPoint(secondaryContext, h+i, v); } CGContextDrawPath(secondaryContext, kCGPathFillStroke); } //a function that sets a different color for each i void SetStrokeColor(int i) { CGContextSetRGBStrokeColor(secondaryContext,… } </code></pre> <p>this code works with a good performance if the line color is always the same.</p> <p>my issue now is that once CGContextDrawPath is called the whole line is drawn in the color of the last CGContextSetRGBStrokeColor.</p> <p>is there a way that the path keeps the colors of every line segment that was added ?</p> <p>any help is greatly appreciated.</p> <p>cheers, bzt</p>