Reputation: 4331
Usually bezier paths have the parameter with 0 <= t <= 1 which describes a certain point on the curve.
What I would like to do is:
I have the 4 points (start, end, 2 control points ) and now I would like to draw a line from t=0 to t=0.5. Is there a standard way to do this in iOS (native framework or open source)?
If this would not be possible I would have to calculate the endpoint and also two new control points on my own.
Upvotes: 1
Views: 687
Reputation: 56625
If you are only interested in drawing that path and not calculating the points to do something else with them, then you could stroke the path only up until t=0.5.
You can do this with a CAShapeLayer
by setting the strokeStart
and strokeEnd
properties. The appearance of the stroke can be properties like strokeColor
and lineWidth
. I recommend that you look at the documentation for the full list of properties.
The code would look something like this (I didn't run this so there may be typos etc.):
CAShapeLayer *halfBezier = [CAShapeLayer layer];
// use the full path
halfBezier.path = [yourFullPath CGPath];
// configure the appearance
halfBezier.fillColor = [[UIColor clearColor] CGColor];
halfBezier.strokeColor = [[UIColor redColor] CGColor];
halfBezier.lineWidth = 2.0;
// 0.0 ≤ t ≤ 0.5
halfBezier.strokeStart = 0.0; // the default value (only here for clarity)
halfBezier.strokeEnd = 0.5; // only up until t=0.5
// add this layer to the view's layer where it is supposed to be drawn
[yourView.layer addSublayer:halfBezier];
Upvotes: 3