Objective c UIView中的圆柱形外观渐变

Objective c UIView中的圆柱形外观渐变,objective-c,ios,uiview,core-graphics,Objective C,Ios,Uiview,Core Graphics,我想画一个圆柱状外观和阴影效果(如下图所示)的酒吧。有人可以帮助定义下面的外观和感觉线性梯度 代码: 这是一个通用渐变生成器: CGGradientRef makeGradient2(NSArray *colors, CGFloat *stops) { size_t nc = 4; NSInteger colorSize = nc * sizeof(CGFloat); CGFloat *theComponents = malloc

我想画一个圆柱状外观和阴影效果(如下图所示)的酒吧。有人可以帮助定义下面的外观和感觉线性梯度

代码:


这是一个通用渐变生成器:

    CGGradientRef makeGradient2(NSArray *colors, CGFloat *stops)
    {
        size_t nc = 4;
        NSInteger colorSize = nc * sizeof(CGFloat);
        CGFloat *theComponents = malloc( [colors count] * colorSize );
        CGFloat *compPtr = theComponents;

        for (int i=0; i < colors.count; i++){
            UIColor *color = [colors objectAtIndex:i];
            CGColorRef cgColor = [color CGColor];
            const CGFloat *components = CGColorGetComponents(cgColor);

            memmove(compPtr, components, colorSize);
            compPtr += nc;
        }
        CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
        CGGradientRef gradient = CGGradientCreateWithColorComponents (cs, theComponents, stops, colors.count);
        CGColorSpaceRelease(cs);
        free(theComponents);

        return gradient;
    }
然后你可以用它来画画(从左到右的渐变):

    CGGradientRef makeGradient2(NSArray *colors, CGFloat *stops)
    {
        size_t nc = 4;
        NSInteger colorSize = nc * sizeof(CGFloat);
        CGFloat *theComponents = malloc( [colors count] * colorSize );
        CGFloat *compPtr = theComponents;

        for (int i=0; i < colors.count; i++){
            UIColor *color = [colors objectAtIndex:i];
            CGColorRef cgColor = [color CGColor];
            const CGFloat *components = CGColorGetComponents(cgColor);

            memmove(compPtr, components, colorSize);
            compPtr += nc;
        }
        CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
        CGGradientRef gradient = CGGradientCreateWithColorComponents (cs, theComponents, stops, colors.count);
        CGColorSpaceRelease(cs);
        free(theComponents);

        return gradient;
    }
    CGFloat stops[] = { 0.0, 0.5, 1.0};
    gradient = makeGradient2([NSArray arrayWithObjects:
                               [UIColor colorWithRed:.2 green:.2 blue:.2 alpha:1.0],
                               [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:1.0],
                               [UIColor colorWithRed:.2 green:.2 blue:.2 alpha:1.0],
                               nil], stops);
    CGContextDrawLinearGradient(gc, gradient, CGPointMake(0.0, 0.0), CGPointMake(rect.size.width, 0.0), 0);