tags:

views:

28

answers:

0

How to draw line continuous in uiview? I have used below code and it works fine but after drawing line straght when i draw another line then first one gets clear if i do not clear that then they join each other. Please suggest some solution.

- (void)drawRect:(CGRect)rect {
    CGContextRef context = UIGraphicsGetCurrentContext();

    //for( Line *eachLine in lineArray )
//        [eachLine drawInContext:context];

    CGContextSetLineWidth(context, 2.0);
    CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
    CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);

    if (firstTouch.x != 0.0 && firstTouch.y != 0.0) {
        CGRect dotRect = CGRectMake(firstTouch.x - 3, firstTouch.y - 3.0, 5.0, 5.0);
        CGContextAddEllipseInRect(context, dotRect);
        CGContextDrawPath(context, kCGPathFillStroke);

        CGContextMoveToPoint(context, firstTouch.x, firstTouch.y);
        for (NSString *onePointString in points) {
            CGPoint nextPoint = CGPointFromString(onePointString);
            CGContextAddLineToPoint(context, nextPoint.x, nextPoint.y);

        }
        CGContextStrokePath(context);
    }
    else {
        CGContextSetFillColorWithColor(context, self.backgroundColor.CGColor);
        CGContextAddRect(context, self.bounds);
        CGContextFillPath(context);
    }
}