The core of drawing a rectangle with a frame on one line

How to draw a rectangle with a border on the same line?

The following methods exist:

CGContextStrokeRect(context, someRectangle); 

and

 CGContextFillRect(context, someRectangle); 

but is there something that does in one?

+6
source share
3 answers
 - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGPathRef path = CGPathCreateWithRect(rect, NULL); [[UIColor redColor] setFill]; [[UIColor greenColor] setStroke]; CGContextAddPath(context, path); CGContextDrawPath(context, kCGPathFillStroke); CGPathRelease(path); } 

Although, I can’t say that this is less detailed than a stroke, and to fill in individual calls ...

+9
source

If you just want to save space in a string, you can define your own method for making two calls and put it in a utility class.

 void strokeAndFill(CGContextRef c, CGRect rect) { CGContextFillRect(c, rect); CGContextStrokeRect(c, rect); } 
+6
source

CGContextDrawPath does this once if you have predefined the fill and stroke color.

 CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetStrokeColor(context, a); CGContextSetFillColor(context, b); CGContextDrawPath(context, rect) 
-1
source

All Articles