views:

742

answers:

1

I'm trying to draw a pill type ellipse, as in Apple's Mail application which displays the number of emails in the inbox. Any idea why the following isn't drawing?

- (void)drawRect:(CGRect)rect 
{ 
   CGContextRef context = UIGraphicsGetCurrentContext();

 CGFloat minX = CGRectGetMinX(rect);
 CGFloat minY = CGRectGetMinY(rect);
 CGFloat maxX = CGRectGetMaxX(rect);
 CGFloat maxY = CGRectGetMaxY(rect);

 CGFloat radius = 3.0; 
 CGContextBeginPath(context);
 CGContextMoveToPoint(context, (minX + maxX) / 2.0, minY);
 CGContextAddArcToPoint(context, minX, minY, minX, maxY, radius);
 CGContextAddArcToPoint(context, minX, maxY, maxX, maxY, radius);
 CGContextAddArcToPoint(context, maxX, maxY, maxX, minY, radius);
 CGContextAddArcToPoint(context, maxX, minY, minX, minY, radius);
 CGContextClosePath(context);

 CGContextDrawPath(context, kCGPathFill);
 CGContextFillPath(context);
}
+2  A: 

I think you've forgotten to set the fill color.

Also, see this question for code to do exactly what you require.

rpetrich
Thank you for the link to the answer. I wish I found that prior to posting and wasting everyone's bandwidth. Thanks rpetrich.
Coocoo4Cocoa
No problem. The old question wasn't easy to find; it took me a few mins and I knew it was there.
rpetrich