2012-04-04 97 views
-1

我想绘制15条水平线,它们之间有20个点的距离。我不明白为什么这个代码不起作用。绘制多行石英2D

- (void)drawRect:(CGRect)rect 
{ 
    // Drawing code 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor); 
    CGContextSetLineWidth(context, 2.0); 
    for (int i=20;i+=20;i<=20*15) { 
     CGContextBeginPath(context); 
     CGContextMoveToPoint(context, 10, i); 
     CGContextAddLineToPoint(context, 310, i); 
     CGContextStrokePath(context); 

    } 

} 

谢谢!

+2

没关系。我是个白痴。我写了for循环错误。 – Cosmin 2012-04-04 10:10:26

回答

1

是,for循环应该是:

for (int i=20; i<=20*15; i+=20) { 
    ... 
}