I use Quartz 2D in a UIView object to draw multiple curves, like this example:

This is the code that I have right now (I missed the calculation of control points and other things):
for (int i = 1; i < points.count; ++i) { CGContextMoveToPoint(context, previousXValue, previousYValue); CGContextAddCurveToPoint(context, firstControlPointXValue, firstControlPointYValue, secondControlPointXValue, secondControlPointYValue, xValue, yValue );
Now I would like to fill the area under the curve, but if I use CGContextFillPath , the result will be as follows:

which makes sense because according to Quartz 2D documentation :
When you fill out the current path, Quartz acts as if every sub-item contained in the path has been closed. He then uses these closed subpaths and calculates the pixels to fill.
Then I tried to move the path to the lower right corner and close the path, but the fill method has no effect:
CGContextMoveToPoint(context, rect.size.width, rect.size.height); CGContextClosePath(context); CGContextFillPath(context);
How could I fill the entire area below the curve, and not just the subarea closed in each subpath?
EDIT:
I found a temporary solution: drawing a figure using a curve and two vertical lines on each subpath:
for (int i = 1; i < points.count; ++i) {
I don't know if this is redundant, so improvements are also welcome. In addition, I get this result:

Note that vertical lines appear as a result of drawing subareas next to each other. How can this be avoided?