不能在iphone中划一条线

时间:2011-11-14 11:53:47

标签: iphone objective-c quartz-graphics

我想绘制一个2像素的线。我已经编写了以下代码,但它没有在视图上绘制任何行或任何内容.Plzz帮助我这个或告诉我这段代码中的错误...在代码中 pointToBeShown CGPoint .....

- (void)drawRect:(CGRect)rect {
    // Drawing code.    
CGContextRef context =  UIGraphicsGetCurrentContext();      
CGContextSetLineWidth(context, 2.0);    
CGContextSetStrokeColor(context, currentColor.CGColor);         
pointToBeShown.x = 30;  
pointToBeShown.y = 449;
CGContextMoveToPoint(context, pointToBeShown.x, pointToBeShown.y);
CGContextAddLineToPoint(context, (pointToBeShown.x + 1),( pointToBeShown.y + 1));
CGContextStrokePath(context); 
}

1 个答案:

答案 0 :(得分:2)

你没有得到任何警告吗?

替换

CGContextSetStrokeColor(context, currentColor.CGColor);         

CGContextSetStrokeColorWithColor(context, currentColor.CGColor);         

<强>更新: 您在评论中提到的更新

CGContextRef context = UIGraphicsGetCurrentContext();
[currentColor set];
CGContextSetLineWidth(context, 2.0);
CGContextFillEllipseInRect(context, CGRectMake(pointToBeShown.x, pointToBeShown.y, 10, 10));