I have an array of CGpoint and I want to connect these points to create a line. I know how to do it by subclass the UIView. but what I want to do here is that I already have an array of CGPoint and I have a button, when I click the button the line will be shown.
I don't know how to do this.
However I try something like following: (aLine is the array with CGPoint)
#define POINT(X) [[aLine objectAtIndex:X]CGPointValue]
CGContextRef context = UIGraphicsGetCurrentContext();
for (int i = 0;i < (aLine.count-1);i++){
CGPoint pt1 = POINT(i);
CGPoint pt1 = POINT(i+1);
CGContextMoveToPoint(context,pt1.x,pt1.y);
CGContextAddLineToPoint(context,pt2.x,pt2.y);
CGContextStrokePath(context);
}
Anyone can help me? thanks.