Question

I have following problem:

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetLineCap(context,kCGLineCapRound);
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetRGBFillColor(context, 1, 0, 0, 1);

for (drawnCurve *line in completeLines) {
CGContextBeginPath(context);    
    for(int i=0;i<[line.points count]-1;i++) 
    { 
    drawnPoint*point=[line.points objectAtIndex:i];
    drawnPoint*point2=[line.points objectAtIndex:i+1];

   // CGContextSetLineWidth(context, point.r);
    [point.color set];
    CGContextMoveToPoint(context, point.x,point.y);
        CGContextAddLineToPoint(context, point2.x, point2.y);  
    // CGContextAddCurveToPoint(context, (point.x+point2.x)/2, point2.y, (point.x+point2.x)/2, point2.y, point2.x, point2.y);

        //CGContextEOFillPath(context);
    }
    CGContextClosePath(context);
    CGContextFillPath(context);
}

But it's just disappearing and not showing any kind of filled curves.. What is the problem?

Was it helpful?

Solution

A call to CGContextMoveToPoint begins a new subpath. You should call it once before your nested for loop, and then use only CGContextAddLineToPoint to preserve line connectivity:

drawnPoint*pointZero=[line.points objectAtIndex:0];
CGContextMoveToPoint(context, pointZero.x,pointZero.y);
for(int i=1;i<[line.points count];i++) 
{ 
    drawnPoint*point=[line.points objectAtIndex:i];
    CGContextAddLineToPoint(context, point.x, point.y);  
}
CGContextClosePath(context);
CGContextFillPath(context);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top