0

我有代码在 uimapview 中使用特定颜色绘制路线。但我需要的是这条线淹没的渐变效果。谁能帮我解决这个问题?我当前的代码放在这里以供参考。

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 是包含创建的图像的最终图像视图。

4

0 回答 0