Wie zeichne ich eine Verlaufslinie (Ein- / Ausblenden) mit Core Graphics / iPhone?

Ich weiß, wie man eine einfache Linie zeichnet:

CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextMoveToPoint(context, x, y);
CGContextAddLineToPoint(context, x2, y2);
CGContextStrokePath(context);

Und ich weiß, wie man ein Farbverlaufsrechteck erstellt, z.

CGColorSpaceRef myColorspace=CGColorSpaceCreateDeviceRGB();
size_t num_locations = 2;
CGFloat locations[2] = { 1.0, 0.0 };
CGFloat components[8] = { 0.0, 0.0, 0.0, 1.0,    1.0, 1.0, 1.0, 1.0 };

CGGradientRef myGradient = CGGradientCreateWithColorComponents(myColorspace, components, locations, num_locations);

CGPoint myStartPoint, myEndPoint;
myStartPoint.x = 0.0;
myStartPoint.y = 0.0;
myEndPoint.x = 0.0;
myEndPoint.y = 10.0;
CGContextDrawLinearGradient (context, myGradient, myStartPoint, myEndPoint, 0);

Aber wie könnte ich eine Linie mit einem Farbverlauf zeichnen, z. Einblenden von Schwarz nach Weiß (und möglicherweise auch Ausblenden nach Schwarz auf der anderen Seite)?

Antworten auf die Frage(5)

Ihre Antwort auf die Frage