[allPoints
removeLastObject];
[self setNeedsDisplay];
}
}
- (void)drawRect:(CGRect)rect
{
if (allPoints.count == 0) {
return;
}
CGContextRef ctx=UIGraphicsGetCurrentContext(); //获取画板,或
者说获取画图上下文。
CGContextSetStrokeColorWithColor(ctx, [UIColor
redColor].CGColor); //设置画笔颜色。
CGContextSetLineWidth(ctx, 1.5); //设置线条宽度。
for (NSMutableArray *points in allPoints) {
for (int i=0;i<points.count-1;i++) {
if (points.count==0) {
break;
}
NSValue *sValue = [points objectAtIndex:i];
CGPoint sPoint=[sValue CGPointValue];
NSValue *eValue = [points objectAtIndex:i+1];
CGPoint ePoint=[eValue CGPointValue];
CGContextMoveToPoint(ctx, sPoint.x, sPoint.y); //前往起点。
CGContextAddLineToPoint(ctx, ePoint.x, ePoint.y); //由起点加
线到终点。
CGContextStrokePath(ctx);
}
}
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSMutableArray *points = [NSMutableArray array];
[allPoints addObject:points];
}
找软件资料,就到一览软件文库