ios 2D繪圖

-(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);

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容