【发布时间】:2013-03-13 10:35:36
【问题描述】:
我的 MKPolyLineView 有问题。我只是尝试为折线制作颜色渐变,但使用 CAGradient 它不起作用。我将 MKPolylineView 子类化并在
中重绘- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
UIColor *darker = [UIColor blackColor];
CGFloat baseWidth = self.lineWidth / zoomScale;
// draw the dark colour thicker
CGContextAddPath(context, self.path);
CGContextSetStrokeColorWithColor(context, darker.CGColor);
CGContextSetLineWidth(context, baseWidth * 1.5);
CGContextSetLineCap(context, self.lineCap);
CGContextStrokePath(context);
// now draw the stroke color with the regular width
CGContextAddPath(context, self.path);
CGContextSetStrokeColorWithColor(context, self.strokeColor.CGColor);
CGContextSetLineWidth(context, baseWidth);
CGContextSetLineCap(context, self.lineCap);
CGContextStrokePath(context);
[super drawMapRect:mapRect zoomScale:zoomScale inContext:context];
}
但即使这样也不起作用(StrokeColor = red)。任何想法如何获得渐变 折线? (高色、中心色、低色)
谢谢大家。
【问题讨论】:
-
您能否发布该项目(或简化版)的完整源代码?
标签: ios objective-c calayer cagradientlayer