CGContext line width

mickm picture mickm · Aug 27, 2013 · Viewed 9.3k times · Source

I'm trying to draw a simple line, the problem is that it is coming out not as 1 pixel in width but 2. The docs state that user space units will translate to a pixel, if I read it correctly.

The code is as simple as it gets, yet my line is always 2 pixels wide.

//Get the CGContext from this view
CGContextRef context = UIGraphicsGetCurrentContext();
//Set the stroke (pen) color
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);

//Set the width of the pen mark
CGContextSetLineWidth(context, 1);

for (int i = 1; i <= sections - 1; i++)
{
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(0.0, i * kSectionHeight)];

    CGContextMoveToPoint(context, 0.0, i * kSectionHeight); //Start point
    CGContextAddLineToPoint(context, self.frame.size.width, i * kSectionHeight);
}

CGContextStrokePath(context);

enter image description here

Answer

uchuugaka picture uchuugaka · Aug 27, 2013

No points don't translate to pixels. If your line is too thick change the value.