I wanted to draw a line using CGContext and what I have so far is:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextSetLineWidth(context, 1.0f);
CGContextMoveToPoint(context, 10, 10);
CGContextAddLineToPoint(context, 100, 50);
CGContextStrokePath(context);
It always draws from the top left corner to the top bottom right corner. How can I adjust the start and end origin of this line? How do I adjust the length of the line?
These two lines are responsible for the start and end points:
By adjusting these two x, y points you can adjust the line. The length of the line depends on the start and end points.
Following on from psoft’s answer – here’s a basic example project of drawing, including creating a path and stroking it.
This is explained in more detail with more sample code in the Quartz 2D guide for paths.