Drawing line Continous.

Posted by japs on Stack Overflow See other posts from Stack Overflow or by japs
Published on 2010-04-02T04:57:15Z Indexed on 2010/04/02 5:03 UTC
Read the original article Hit count: 322

Filed under:

Hi All,

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

© Stack Overflow or respective owner

Related posts about iphone