uiimageretina-displayuibezierpathcgcontextref

create a UIBezierPath of 3 pixels width on retina @2x display


I'm trying to create a line of 3 pixels width on a retina @2x display. The simple idea would be to create a 1.5 width line :

UIGraphicsBeginImageContextWithOptions(CGSizeMake(20, 20), NO, 0.0f);
CGContextRef aRef = UIGraphicsGetCurrentContext();
CGContextSetAllowsAntialiasing(aRef, NO);
CGContextSetShouldAntialias(aRef, NO);
UIBezierPath* bezierPath = UIBezierPath.bezierPath;
[bezierPath moveToPoint: CGPointMake(10, 0)];
[bezierPath addLineToPoint: CGPointMake(10, 10)];
bezierPath.lineWidth = 1.5;
[bezierPath stroke];
UIImage * myImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

But at the end, I end up with a 4 pixels line width on screen.

The thing is, I'm using the iPad 3 (so retina @2x), and when I use a UIBarButtonItem with the predefined system button UIBarButtonSystemItemAdd, the two paths of the cross are 3 pixels width on my screen.


Solution

  • It worked with :

    UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRect: CGRectMake(13, 21, 18, 1.5)];