I am having code to draw route with a specific color in uimapview. But i need is a gradient effect for this line drown. Can anyone please help me to solve this provlem? my current code i put here for 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;
Here routes containing my latitude logitude array, line color i am initializing before. routeView is the final imageview which contains the image created.