Sundeep Manne
Sundeep Manne

Reputation: 5

How to clear drawrect in Ios?

I came up with a scenario like drawing a line graph using DrawRect method. Using the same code i should plot three more types of line graphs. How should i clear already plotted graph and draw another...Posting one of the clasess drawRect method. Please look at it and suggest me a solution for this

- (void)drawRect:(CGRect)rect 
{
     CGContextRef context = UIGraphicsGetCurrentContext();
     CGContextClearRect(context, self.bounds);
     CGContextSetAllowsAntialiasing(context, true);

    CGRect currentBounds = self.bounds;
    CGFloat dotsWidth = self.numberOfPages*kDotDiameter + MAX(0,     self.numberOfPages-1)*kDotSpacer;
    CGFloat x = CGRectGetMidX(currentBounds)-dotsWidth/2;
    CGFloat y = CGRectGetMidY(currentBounds)-kDotDiameter/2;
    for (int i=0; i<_numberOfPages; i++)
    {
        CGRect circleRect = CGRectMake(x, y, kDotDiameter, kDotDiameter);
        if (i == _currentPage)
        {
            CGContextSetFillColorWithColor(context, [UIColor orangeColor].CGColor);
        }
       else
       {
           CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
       }
        CGContextFillEllipseInRect(context, circleRect);
        x += kDotDiameter + kDotSpacer;
    }
}

Upvotes: 0

Views: 2395

Answers (1)

gabbler
gabbler

Reputation: 13766

You can try the following, rect should be containing the line graph bounds.

CGContextClearRect(UIGraphicsGetCurrentContext(), rect);

Upvotes: 2

Related Questions