i’m using drawRect inside a custom UIButton to draw a bordered button with an image inside. The code is the following:
- (void) drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
//Draw a rectangle
CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
CGContextSetStrokeColorWithColor(context, [[UIColor grayColor] CGColor]);
//Define a rectangle
CGRect drawrect = CGRectMake(CGRectGetMinX(rect),CGRectGetMinY(rect),rect.size.width,rect.size.height);
CGContextStrokeRect(context,drawrect);}
The problem is that on corners i got an extra pixel (see the attached image). What am i doing wrong?

thanks
You are drawing your rectangle along the edges of pixels, instead of drawing it along the centers of pixels. So your rectangle only covers half of most pixels. On the corners it covers three-quarters of the pixels.
To draw along the pixel centers, you have to use half-integer coordinates. Try this: