Coocoo4Cocoa
Coocoo4Cocoa

Reputation: 50916

CoreGraphics on iPhone, trying to draw a "pill" type ellipse

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);
}

Upvotes: 0

Views: 2433

Answers (1)

rpetrich
rpetrich

Reputation: 32346

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

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

Upvotes: 3

Related Questions