0

I want to add fill color to a circle. This code dont work:

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, 2.0);
    CGContextSetRGBStrokeColor(context, 0, 0, 225, 1);
    CGContextSetRGBFillColor(context, 0, 255, 0, 1);
    CGContextAddArc(context, pointWhereUserClickedX, pointWhereUserClickedY, 50, 0, 2*3.14159265359, YES);
    CGContextDrawPath(context, kCGPathStroke);

What is wrong?

Nathaniel Waisbrot
  • 23,261
  • 7
  • 71
  • 99

2 Answers2

0

Must use in the last line this:

CGContextDrawPath(context, kCGPathFillStroke);

jackdev23
  • 116
  • 4
  • If doesn't work please check that drawRect is called by using setNeedsDisplay. In my solution I have a UIView and the above code is in drawRect. If you want a more detailed answer add more code, please. – jackdev23 Feb 28 '13 at 09:21
0

you did not fill the circle with the fill color.

 - (void)drawRect:(CGRect)rect { 
     //your code and add this line:
     CGContextFillEllipseInRect(contextRef, rect);
   }
james075
  • 1,280
  • 1
  • 12
  • 22