开发者

How would I draw this using CGContext

开发者 https://www.devze.com 2022-12-21 20:02 出处:网络
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

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.

How would I draw this using CGContext


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);


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号