Because your current position is changed after you draw second ellipse CGContextAddEllipseInRect(context, rectangle2);
Try this:
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor * w = [UIColor whiteColor] ;
UIColor * r = [UIColor redColor] ;
CGContextSetStrokeColorWithColor(context, w.CGColor) ;
CGContextSetFillColorWithColor(context, r.CGColor) ;
if (!CGPointEqualToPoint(first, CGPointZero)) {
CGRect rectangle = CGRectMake(first.x - 10, first.y - 10, 20, 20);
CGContextAddEllipseInRect(context, rectangle);
CGContextMoveToPoint(context, first.x, first.y);
if (!CGPointEqualToPoint(second, CGPointZero)) {
CGContextAddLineToPoint(context, second.x, second.y);
CGRect rectangle2 = CGRectMake(second.x - 10, second.y - 10, 20, 20);
CGContextAddEllipseInRect(context, rectangle2);
CGContextMoveToPoint(context, second.x, second.y);
}
if (!CGPointEqualToPoint(third, CGPointZero)) {
CGContextAddLineToPoint(context, third.x, third.y);
CGRect rectangle3 = CGRectMake(third.x - 10, third.y - 10, 20, 20);
CGContextAddEllipseInRect(context, rectangle3);
}
CGContextStrokePath(context);
}
}