0

I'm trying to draw a rectangle, which should have black color border of width 5.0, I am getting the rectangle as seen below,

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextStrokePath(context);
CGContextSetRGBFillColor(context, 0.0, 1.0, 0.0, 0.5);
CGContextFillRect(context, rect);

enter image description here

I can make it clear / transparent (white) background instead the green one showing right now with [UIColor whiteColor].CGColor but then it should have black border also.

How do I set the customized border to rectangle?

Hemang
  • 26,840
  • 19
  • 119
  • 186

1 Answers1

5

Set the stroke color and width as desired, for example:

CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextSetLineWidth(context, 5.0f);
CGContextStrokeRect(context, rect);

If you are also filling the rectangle, do this after filling so the fill doesn't cover up the stroke.

Arkku
  • 41,011
  • 10
  • 62
  • 84