How to Draw Thin Lines Using Core Graphics
When creating my own custom graphing engine I had wanted to have very thin (1px) grid lines so that the data lines would stand out by being thicker. Now you might be thinking well by default when using CG drawing the lines are 1px. This is true but when they are draw half a pixel is drawn on each side making them 2px lines.There is a trick however to overcome this, and it is to offset the lines start and end point by half a pixel in the y-axis. This prevents CG from drawing the added half pixel on each side. So in effect you get a true 1px line.
So for example if your line was going to be from (10 , 30) to (20 , 30) instead make it from (10 , 30.5) to (20 , 30.5)
Hope this helps:)
Filed under: Tutorials | Leave a Comment
Tags: cocoa, core graphics, draw, iphone, lines, thin, tutorial