-(void)drawRect:(CGRect)rect{
//刻度尺 或者迷宫游戏
ctx=UIGraphicsGetCurrentContext();
width=10;
endx=320;
endy=480;
[selfDrawWidthLine:CGPointMake(0,0)endPoint:CGPointMake(endx,endy)];
// [self DrawWidthLine:CGPointMake(endx, 0) endPoint:CGPointMake(0, endy)];
// [self DrawWidthLine:CGPointMake(0, endy/2) endPoint:CGPointMake(endx, endy/2)];
// [self DrawWidthLine:CGPointMake(endx/2, 0) endPoint:CGPointMake(endx/2, endy)];
}
//绘制一根有宽度的线(绘制斜的四边形)
-(void)DrawWidthLine:(CGPoint)start endPoint:(CGPoint)end{
CGContextMoveToPoint(ctx, start.x, start.y);
CGContextAddLineToPoint(ctx, end.x, end.y);
CGContextSetLineWidth(ctx,width);
CGContextStrokePath(ctx);
}
//绘制一根线
-(void)DrawlinePoint1:(CGPoint)start endPoint:(CGPoint)end{
CGContextMoveToPoint(ctx, start.x,start.y);
CGContextAddLineToPoint(ctx, end.x, end.y);
CGContextStrokePath(ctx);
}
//使用path绘制一根线
-(void)DrawlinePoint:(CGPoint)start endPoint:(CGPoint)end{
CGMutablePathRefpath=CGPathCreateMutable();
CGPathMoveToPoint(path,NULL, start.x, start.y);
CGPathAddLineToPoint(path,NULL, end.x, end.y);
CGContextAddPath(ctx, path);
CGContextStrokePath(ctx);
}
//绘制一个圆形
-(void)DrawCicleWithRect:(CGRect)rect{
CGMutablePathRefpath=CGPathCreateMutable();
CGPathAddEllipseInRect(path,NULL, rect);
CGContextAddPath(ctx, path);
CGContextStrokePath(ctx);
}
//绘制一个四边形
-(void)DrawRectWithPoint1:(CGPoint)point1 Point2:(CGPoint)point2 Point3:(CGPoint)point3 Point4:(CGPoint)point4{
CGContextMoveToPoint(ctx, point1.x, point1.y);
CGContextAddLineToPoint(ctx, point2.x, point2.y);
CGContextAddLineToPoint(ctx, point3.x, point3.y);
CGContextAddLineToPoint(ctx, point4.x, point4.y);
CGContextAddLineToPoint(ctx, point1.x, point1.y);
CGContextStrokePath(ctx);
}
//使用path绘制一个四边形
-(void)DrawRectWithPoint11:(CGPoint)point1 Point2:(CGPoint)point2 Point3:(CGPoint)point3 Point4:(CGPoint)point4{
CGMutablePathRefpath=CGPathCreateMutable();
CGPathMoveToPoint(path,NULL, point1.x, point1.y);
CGPathAddLineToPoint(path,NULL,point2.x, point2.y);
CGPathAddLineToPoint(path,NULL, point2.x, point2.y);
CGPathAddLineToPoint(path,NULL, point3.x, point3.y);
CGPathAddLineToPoint(path,NULL, point4.x, point4.y);
CGContextAddPath(ctx, path);
CGContextStrokePath(ctx);
}
//绘制一个四边形
-(void)DrawRecxtWithFrame:(CGRect)rect{
CGContextAddRect(ctx, rect);
CGContextStrokePath(ctx);
}
//填充一个四边形
-(void)StrokeRectWithFrame:(CGRect)rect{
//CGContextStrokeRect(ctx, rect);
//CGContextFillRect(ctx, rect);
UIRectFill(rect);
}