Clear a drawing in drawRect
<p>How can I clear a drawing in a subview? What should I put in my (void)clearLine below?</p>

<pre><code>- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {

    // Setup subview to draw a line

    CGRect subviewRect = CGRectMake(0, 0, 250, 300);
    Draw* _draw = [[Draw alloc] initWithFrame:subviewRect];
    _draw.exclusiveTouch = NO;
    _draw.backgroundColor = [UIColor clearColor];
    [self addSubview:_draw];
    }
    return self;
}

- (void) clearLine
    {
    // how can I clear the drawing in Draw
    }
</code></pre>

<p>And below is the Draw.m file, that will draw a straight line by getting the first touch as the starting point and the second touch as the ending point.</p>

<pre><code>@implementation Draw

- (void)drawRect:(CGRect)rect {

    CGPoint fromPoint;
    CGPoint toPoint;

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetLineWidth(context, 2.0);
    CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
    CGFloat components[] = {0.0, 0.0, 1.0, 1.0};
    CGColorRef color = CGColorCreate(colorspace, components);
    CGContextSetStrokeColorWithColor(context, color);
    CGContextSetLineCap(context, kCGLineCapRound);

    CGContextMoveToPoint(context, fromPoint.x, fromPoint.y);
    CGContextAddLineToPoint(context, toPoint.x, toPoint.y);
    CGContextStrokePath(context);
    CGColorSpaceRelease(colorspace);
    CGColorRelease(color);
}    

// Touch event
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch* touchPoint = [touches anyObject];
    fromPoint = [touchPoint locationInView:self];
    toPoint = [touchPoint locationInView:self];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch* touch = [touches anyObject];
    toPoint = [touch locationInView:self];    
    [self setNeedsDisplay];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch* touch = [touches anyObject];
    toPoint = [touch locationInView:self];    
    [self setNeedsDisplay];
}
</code></pre>
