1

unfortunately I can't get to a solution with drawing a radial gradient in my UIView.

Look...that's how I want to draw it (this was made in PS): enter image description here

But I'm currently stuck on this: enter image description here

That's my code:

CGGradientRef radialGradient;
CGColorSpaceRef rgbColorspace;

size_t num_locations = 2;
CGFloat locations[2] = { 0.0, 1.0 };
const CGFloat *colorComponents = CGColorGetComponents(textColor.CGColor);
CGFloat components[8] = { colorComponents[0], colorComponents[1], colorComponents[2], 1.0,  // Start color
    1.0, 1.0, 1.0, 1.0 }; // End color

rgbColorspace = CGColorSpaceCreateDeviceRGB();
radialGradient = CGGradientCreateWithColorComponents(rgbColorspace, components, locations, num_locations);

CGRect currentBounds = self.bounds;
CGPoint midCenter = CGPointMake(CGRectGetMidX(currentBounds), CGRectGetMidY(currentBounds));

CGContextDrawRadialGradient(myContext, radialGradient, midCenter, 8.0, midCenter, 1.0, kCGGradientDrawsAfterEndLocation);



CGGradientRelease(radialGradient);
CGColorSpaceRelease(rgbColorspace);

I hope someone can give me the right tip ;)

Enjoy the weekend, Chris

4

1 回答 1

2

基本上,您需要使用 2 个以上的位置。使用 2 个位置,您可以在开始位置和结束位置之间获得恒定梯度。您的示例图像显示了大多数位置的开始颜色,直到结束,而结束颜色则更加苍白。查看示例图像,您将需要至少 3 个位置并更改最终颜色。

于 2013-10-26T09:07:19.710 回答