CGContextRef inset?

201 views Asked by At

So, I have this code, that draws a circle with a line around it.

- (void)drawRect:(CGRect)rect
{
    CGContextRef contextRef = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(contextRef, 40.0);
    CGContextSetRGBFillColor(contextRef, 0.0, 0.0, 0.0, 1.0);
    CGContextSetRGBStrokeColor(contextRef, 132.0/255.0, 128.0/255.0, 128.0/255.0, 1.0);
    CGContextFillEllipseInRect(contextRef, rect);
    CGContextStrokeEllipseInRect(contextRef, rect);
}

The problem is that half of the width of the line falls outside the rect. So, what I would like to do, is to create an inset relative to the line width, to compensate for this. Or maybe there is a method, that tells my line to remain inside the boundaries of the circle?

1

There are 1 answers

1
Snowman On BEST ANSWER

Before filling,

rect = CGRectInset(rect, 1, 1);