简单作图

CGContextRef context = UIGraphicsGetCurrentContext();
//画菱形
CGContextSetLineWidth(context, 5);
CGPoint points[5];
points[0] = CGPointMake(200, 350);
points[1] = CGPointMake(300, 400);
points[2] = CGPointMake(200, 450);
points[3] = CGPointMake(100, 400);
points[4] = CGPointMake(200, 350);
CGContextAddLines(context, points, 5);
CGContextStrokePath(context);
//画多个矩形
CGRect rcts[4];
rcts[0] = CGRectMake(100, 100, 200, 200);
rcts[1] = CGRectMake(90, 110, 200, 200);
rcts[2] = CGRectMake(80, 120, 200, 200);
rcts[3] = CGRectMake(70, 130, 200, 200);
CGContextAddRects(context, rcts, 4);
CGContextStrokePath(context);
//画椭圆
CGContextSetRGBStrokeColor(context, 1, 0, 0, 1);
CGContextSetLineWidth(context, 5.0);
CGContextAddEllipseInRect(context, CGRectMake(10, 10, 100, 30));
CGContextStrokePath(context);
//画曲线
CGContextSetRGBStrokeColor(context, 0, 1, 0, 1);
CGContextMoveToPoint(context, 50, 50);
CGContextSetLineWidth(context, 5.0);
CGContextAddQuadCurveToPoint(context, 150, 100, 300, 400);
CGContextAddCurveToPoint(context, 100, 100, 150, 200, 150, 450);
CGContextStrokePath(context);
//自定义弧线
void CGContextAddArc (
    CGContextRef c,
    CGFloat x,			
    CGFloat y,			
    CGFloat radius,		
    CGFloat startAngle,	
    CGFloat endAngle,		
    int clockwise			
);
CGContextSetRGBStrokeColor(context, 0, 1, 0, 1);
CGContextSetLineWidth(context, 5.0);
{
    float pi = 3.1415926;
    CGContextAddArc(context, 160, 100, 80,100, pi / 2, 0);
}
{
    CGContextMoveToPoint(context, 50, 100);
    CGContextAddArcToPoint(context, 50, 150, 100, 150, 30);
}
CGContextStrokePath(context);

你可能感兴趣的:(ios,iPhone)