2011-01-12 12 views
0

Ich benutze folgenden Code für Drawing Arc in DrawRect ... Ich möchte Arc nur mit Farbverlauf-Effekt zeichnen ... irgendwelche Hilfe bitte?Farbverlauf in CGContextAddArc?

   CGContextSetAlpha(ctx, 0.5); 
      CGContextSetRGBFillColor(ctx, color.red, color.green, color.blue, color.alpha); 
      CGContextMoveToPoint(ctx, cX, cY); 
      CGContextAddArc(ctx, cX, cY, radious+10, (startDeg-90)*M_PI/180.0, (endDeg-90)*M_PI/180.0, 0); 
      CGContextClosePath(ctx); 
      CGContextFillPath(ctx); 

Antwort

1

Zuerst erzeugt ein Lichtbogen dann den folgenden Code verwendet Steigungseffekt auf den Pfad anzuwenden,

CGGradientRef glossGradient; 
CGColorSpaceRef rgbColorspace; 
size_t num_locations = 2; 
CGFloat locations[2] = { 0.0, 1.0 }; 
CGFloat components[8] = { 0.965, 0.965, 0.965, 1.0, // Start color 
    0.603, 0.603, 0.603, 1.0 }; // End color 

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

CGRect currentBounds = self.bounds; 
CGPoint topCenter = CGPointMake(CGRectGetMidX(currentBounds), 0.0f); 
CGPoint midCenter = CGPointMake(CGRectGetMidX(currentBounds), CGRectGetMaxY(currentBounds)); 
CGContextDrawLinearGradient(UIGraphicsGetCurrentContext(), glossGradient, topCenter, midCenter, 0); 

CGGradientRelease(glossGradient); 
CGColorSpaceRelease(rgbColorspace);