0

I am having a very weird problem with drawing a rectangle in a cell, as it is drawing the cell, however when it displays there is a discrepancy in the border color, I have searched around and haven't found anything that can shed some light on why this might be, this is a screenshot displaying the problem http://screencast.com/t/wPS507Bg9e

This is the code of how i'm drawing the rectangle

CGRect rect = CGRectMake(x, y, aRect.size.width, height);

CGContextMoveToPoint(context, rect.origin.x, rect.origin.y + radius);
CGContextAddLineToPoint(context, rect.origin.x, rect.origin.y + rect.size.height);
CGContextAddLineToPoint(context, rect.origin.x + rect.size.width, rect.origin.y + rect.size.height  );
CGContextAddLineToPoint(context, rect.origin.x + rect.size.width, rect.origin.y + radius);
CGContextAddArc(context, rect.origin.x + rect.size.width - radius, rect.origin.y + radius, radius, ((0.0f) / 180.0 * M_PI), ((-90.0f) / 180.0 * M_PI) , 1);
CGContextAddLineToPoint(context, rect.origin.x + radius, rect.origin.y);
CGContextAddArc(context, rect.origin.x + radius, rect.origin.y + radius, radius, ((-90.0f) / 180.0 * M_PI), ((180.0f) / 180.0 * M_PI), 1);    

CGContextClip(context);

Another weird thing about this problem is it seems to be only effecting the iPhone 5 and 5s, aka 4" screens only

The colour is being set once and is not manipulated after it is being set as far as i can see , any help on why this would be would be apreciated

Andre Silva
  • 4,782
  • 9
  • 52
  • 65
Jetpack
  • 578
  • 1
  • 5
  • 22

1 Answers1

0

There is no discrepancy in the color itself, but in the actual location (origin), dimensions (size), of your rectangles, or both.

From your screen shot, they are naturally anti-aliased.

This could be because:

  1. The x, y, width & height are not all four discrete values (integers).
  2. Line drawing falls between pixels or stretching an offscreen buffer (anti-aliasing)
  3. Drawing in an improperly constructed retina offscreen buffer? See this post
Community
  • 1
  • 1
SwiftArchitect
  • 47,376
  • 28
  • 140
  • 179
  • I have tried changing rect to CGRect rect = CGRectMake(0, 80, 30, 0); and this however does not change anything, or am i misinterpreting what you mean by changing the origin and size to integers? – Jetpack Jul 08 '14 at 00:59
  • Looking at your screen shot under magnification, I see that the color is correct, but the aliasing is different from one roundrect to the next. The thickness of the edge is not constant, causing the appearance of a different color. I have copied your snippet above in my own code, and am able to reproduce the very same issue on non-retina display. That code is not at fault ; are you working in an offscreen buffer, not matching the resolution or dimensions? Stretching the image maybe? – SwiftArchitect Jul 08 '14 at 02:21