0

The code below in my drawRect method draws a rectangle on my view controller. I'd like to set a corner radius to this. What am I missing?

CGRect rectangle = CGRectMake(20, 22, 280, 460);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, 255, 255, 255, 1.0);
CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);
CGContextFillRect(context, rectangle);
lbudge
  • 11
  • 1
  • 2
  • not a duplicate - your suggestion draws a corner outline and does not apply to my existing object – lbudge May 01 '14 at 19:57
  • 1
    the link is fine. you can stroke the rounded rectangle, you can fill it, or you can do both. – Michael May 01 '14 at 20:00

1 Answers1

6

Try following, please:

CGRect rectangle = CGRectMake(20, 22, 280, 460);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, 255, 255, 255, 1.0);
CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);
//CGContextFillRect(context, rectangle);

UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect: rectangle cornerRadius:15.0];

[bezierPath fill];
Avt
  • 16,927
  • 4
  • 52
  • 72
  • I still think your question is a duplicate of http://stackoverflow.com/questions/2835448/how-to-draw-a-rounded-rectangle-in-core-graphics-quartz-2d – Avt May 01 '14 at 20:42
  • Swift: fillColor.setFill(); let path = UIBezierPath(roundedRect: rect, cornerRadius: cornerRadius); path.fill(); – NikeAlive Jan 22 '19 at 03:19