Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGContext line width

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

like image 519
mickm Avatar asked Aug 27 '13 00:08

mickm


Video Answer


1 Answers

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

like image 160
uchuugaka Avatar answered Sep 23 '22 23:09

uchuugaka