我对以下代码的工作方式感到困惑。预计会产生一个被彩色圆圈包围的黑色圆盘。它适用于某些颜色(如评论中所述),但不适用于其他颜色。谁能解释这种神秘的行为?
- (void)drawRect:(CGRect)rect
{
CGRect rectangle; CGFloat shiftVal=2.0,lineWidth=3.0;
rectangle.origin=CGPointMake(shiftVal, shiftVal);
rectangle.size=self.frame.size;
rectangle.size.width-=shiftVal*2;
rectangle.size.height-=shiftVal*2;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 1.0);
CGContextFillEllipseInRect(context, rectangle);
CGContextSetLineWidth(context, lineWidth);
const CGFloat *components = CGColorGetComponents([UIColor greenColor].CGColor); // Works as expected.
//const CGFloat *components = CGColorGetComponents([UIColor darkGrayColor].CGColor); // No surrounding circle (instead of darkGray).
//const CGFloat *components = CGColorGetComponents([UIColor lightGrayColor].CGColor); // Produces a greenish circle (instead of lightGray)
// Draw the outer circle:
CGContextSetRGBStrokeColor(context,
components[0],
components[1],
components[2],
components[3]);
CGContextStrokeEllipseInRect(context, rectangle);
}