I want to draw this in my view to draw this line, I have everything I need to make a basic line, but am just not good at drawing, I did in fact try to do this, but just cannot get it to work correctly.
+2
A:
Is this a Bézier curve? If you know where the two control points are located, use
CGContextMoveToPoint(context, x, y);
CGContextAddCurveToPoint(context, ...); // Cubic Bézier curve
or
CGContextMoveToPoint(context, x, y);
CGContextAddQuadCurveToPoint(context, ...); // Quadratic Bézier curve
to insert the curve, then use
CGContextStrokePath(context);
to stroke the curve.
KennyTM
2010-03-02 11:07:04
I kind of wanted some actual points. I am not the best Quarts drawer...
Jaba
2010-03-02 12:33:15
@Jaba: You don't even provide the numbers (widths, heights, the position of the 3 highlighted points), how can anyone provide the actual points.
KennyTM
2010-03-02 12:59:11
+1
A:
The following code should draw a sine curve like the one you describe, assuming currentBounds is the bounding rectangle for your area to draw within:
CGContextBeginPath(context);
CGContextMoveToPoint(context, 0.0f, CGRectGetMidY(currentBounds));
CGContextAddCurveToPoint(context, currentBounds.size.width / 5.0f, CGRectGetMidY(currentBounds) - currentBounds.size.width / 5.0f, CGRectGetMidX(currentBounds) - currentBounds.size.width / 5.0f, CGRectGetMidY(currentBounds) - currentBounds.size.width / 5.0f, CGRectGetMidX(currentBounds), CGRectGetMidY(currentBounds));
CGContextAddCurveToPoint(context, CGRectGetMidX(currentBounds) + currentBounds.size.width / 5.0f, CGRectGetMidY(currentBounds) + currentBounds.size.width / 5.0f, currentBounds.size.width - currentBounds.size.width / 5.0f, CGRectGetMidY(currentBounds) + currentBounds.size.width / 5.0f, currentBounds.size.width, CGRectGetMidY(currentBounds));
CGContextClosePath(context);
CGContextStrokePath(context);
Brad Larson
2010-03-03 03:08:36