How to draw more precise lines using basic graphics and CALayer

Hello, I am having a hard time getting this UI element to look the way I want ( see screenshot ). Notice the image on the right - how the line width and darkness look inconsistent compared to the image on the left (which turns out to be a screen capture from a safari) where the border widths are more consistent. How does an apple make its lines so perfect?

I am using CALayer and Core Graphics API to draw an image to the right. Is it possible to draw such perfect lines with a standard apis?

+2


a source to share


2 answers


The problem with drawing a 1 pixel path is that Quartz draws paths on a precise grid of points, starting at {0,0}. This means that if you stroke a vertical path starting at {10,10} with a 1-point width, half of that line will appear in a pixel to the left of the coordinate and half in a pixel to the right, causing a blur effect.

Therefore, you must translate your drawing to {0.5,0.5} if you want the lines to be drawn at precise pixels.



You can definitely paint what you want with quartz.

+10


a source


Apple uses images for tabs.



-1


a source







All Articles