【发布时间】:2013-12-17 11:00:14
【问题描述】:
在一个应用程序中,我绘制了一个弯曲的 UIBezierPath 和一个 MKOverlayPathView 类来显示飞行路线。这是我正在使用的代码:
- (UIBezierPath *)pathForOverlayForMapRect:(MKMapRect)mapRect { ... bla bla bla ... UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:s]; [path addQuadCurveToPoint:e controlPoint:cp1]; [path addLineToPoint:e2]; [path addQuadCurveToPoint:s2 controlPoint:cp2]; [path closePath]; return path; }
- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context{
self.mapRect = mapRect;
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0);
CGContextSetLineWidth(context, mapRect.size.height/700);
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextAddPath(context, [self pathForOverlayForMapRect:mapRect].CGPath);
[self updateTouchablePathForMapRect:mapRect];
CGContextDrawPath(context, kCGPathFillStroke);
}
这工作得很好,但我想沿着该路径绘制一个渐变,而不仅仅是填充颜色。这就是它开始变得非常棘手的地方。
我已经尝试过 CGContextDrawLinearGradient(),但它还没有让我有任何用处。
【问题讨论】:
标签: ios objective-c gradient uibezierpath