views:

306

answers:

3

Whenever I stroke a path with rounded corners on iPhone, the rounded corners are thicker than the rest of the stroked path. See here for what I mean:

rounded corner thickness

Not sure why this happens, any ideas?

A: 

It just looks thicker. If you zoom in on it you will see what looks like a couple extra pixels of black is actually some pixels of gray caused by antialiasing.

Try turning off antialiasing to see if the result looks better.

Edit: Also the bottom right corner seems to have a drop shadow effect.

Brandon Bodnár
You're right, it is the gray pixels that are making that effect. I tried turning antialiasing off, but the result is worse, some parts of the stroke line are missing. Any other way to fix it?
macatomy
Sorry. Not off the top of my head. Hopefully someone else can come by and suggest another way.
Brandon Bodnár
A: 

I suspect that you're drawing within a rectangular clipping path; the corners fall completely within the rectangle, but the sides get cut in half: half inside the clipping path and so drawn, half outside and so clipped out.

Try adding the path to the clipping path before stroking it.

To do this, you will need to add the CGPath to the context's current path twice:

  1. Add CGPath to current path.
  2. Add current path to clipping path (thereby emptying current path).
  3. Add CGPath to current path.
  4. Stroke current path.
Peter Hosey
+2  A: 

I agree with Peter Hosey's analysis that the outer half of your lines is getting clipped off, but my recommendation would be to move all the coordinates .5 pixels inward instead. This way your straight lines will be crisper (not antialiased across 2 screen pixels) as well.

Kevin Reid
Moving it in half a pixel seemed to have fixed the issue, thanks.
macatomy