我知道如何绘制简单的线条:如何使用Core Graphics/iPhone绘制渐变线(淡入/淡出)?
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextMoveToPoint(context, x, y);
CGContextAddLineToPoint(context, x2, y2);
CGContextStrokePath(context);
而且我知道如何做一个渐变的矩形,i.g:
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);
但我怎么能画一条线的渐变,胃内从黑色渐变为白色(也可能在另一侧渐渐变黑)?
快速注释 - 此处选择的答案不正确。 **这是可能的笔画任意路径与梯度**作为[这个答案](http://stackoverflow.com/a/25034854/2547229)显示。 – Benjohn 2015-05-22 12:48:26