我有代码在uimapview中绘制具有特定颜色的路线。但我需要的是这条线淹没的渐变效果。有人可以帮我解决这个问题吗?我现在的代码我放在这里为了referance。
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
routeView=(UIImageView*)[routeDict objectForKey:[placemarkarray objectAtIndex:2]];
lineColor=(UIColor *)[colors objectAtIndex:routeView.tag];
CGContextRef context = CGBitmapContextCreate(nil,
routeView.frame.size.width,
routeView.frame.size.height,
8,
4 * routeView.frame.size.width,
colorSpace,
kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);
CGContextSetStrokeColorWithColor(context, lineColor.CGColor);
CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1.0);
CGContextSetLineWidth(context, 3.0);
for(int i = 0; i < routes.count; i++) {
CLLocation* location = [routes objectAtIndex:i];
CGPoint point = [mapView convertCoordinate:location.coordinate toPointToView:routeView];
if(i == 0) {
CGContextMoveToPoint(context, point.x, routeView.frame.size.height - point.y);
} else {
CGContextAddLineToPoint(context, point.x, routeView.frame.size.height - point.y);
}
}
CGContextStrokePath(context);
CGImageRef image = CGBitmapContextCreateImage(context);
CGContextRelease(context);
UIImage* img = [UIImage imageWithCGImage:image];
CGImageRelease(image);
routeView.image = img;
此处包含我的纬度逻辑数组的路线,我正在初始化的线条颜色。 routeView是包含所创建图像的最终图像视图。