Je suis intrigué par la façon dont le code suivant fonctionne. Il est prévu de produire un disque noir entouré d'un cercle coloré. Cela fonctionne bien avec certaines couleurs (comme expliqué dans les commentaires), mais pas avec d'autres. Quelqu'un peut-il expliquer ce comportement mystérieux?Différents comportements pour différentes couleurs dans drawRect:
- (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);
}
avant d'approfondir ce sujet - vous savez ce qui est une bonne idée si quelque chose ne * ressemble pas * comme prévu? Images!!! 2 ou 3 captures d'écran seraient parfaites. – luk2302
Remplacez l'appel de 'CGContextSetRGBStrokeColor' par une simple ligne:' [[UIColor someColor] setStroke]; '. – rmaddy