我想出了一个场景,比如使用DrawRect方法绘制折线图。使用相同的代码,我应该再绘制三种类型的折线图。我应该如何清除已绘制的图形和绘制another...Posting的无类drawRect方法之一。请看一下,并给我一个解决方案
- (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;
}
}发布于 2014-10-26 13:45:42
你可以尝试下面的方法,rect应该包含线图的边界。
CGContextClearRect(UIGraphicsGetCurrentContext(), rect);https://stackoverflow.com/questions/26570159
复制相似问题