Quartz2D 画大白

今天初始Quartz2D,我好激动啊,也好开心,莫名的会喜欢带有图形相关的课程……

好啦,闲话少说,今天用Quartz2D方法画了最最爱的大白。迫不及待的想要和大家分享。

1、首先实例化了view

2、在实例化的view的写代码就可以了,是不是很简单。

//不允许直接调用drawRect方法,使用setNeedsDisplay 间接调用drawRect方法

- (void)drawRect:(CGRect)rect {

    

    //获得图形上下文

    //获得当前图形上下文

    CGContextRef  context = UIGraphicsGetCurrentContext();

    

    //头

    [self drawHeader:context];

    [self drawHeader2:context];

   

    

    //眼睛

    [self drawEye:context];

    [self drawEye2:context];

    [self drawEye3:context];

    [self drawEye4:context];

    [self drawEyeLine:context];

    

    //身体

    [self drawBody:context];

    [self drawBody2:context];

    [self drawBody3:context];

    [self drawBody4:context];

    [self drawBody5:context];

    

    //脚

    [self drawBody6:context];

    [self drawBody7:context];

}

#pragma mark 画头(上边)

- (void)drawHeader :(CGContextRef) context{

    

    // 1.  圆心 ,半径,起始和终止角度 ,方向

    CGContextAddArc(context, self.frame.size.width/2, 150, 50, 0,- M_PI, 1);

    CGContextStrokePath(context);

    

}

#pragma mark 画头(下边)

- (void)drawHeader2 :(CGContextRef) context{

    

    // 1.  圆心 ,半径,起始和终止角度 ,方向

    CGContextAddArc(context, self.frame.size.width/2, 150, 50, 0,- M_PI, 0);

    CGContextStrokePath(context);

    

}

#pragma mark 眼睛(左下)

-(void)drawEye:(CGContextRef) context{

    

    CGContextAddArc(context, 162, 160, 10, 0,- M_PI, 0);

    CGContextFillPath(context);

    

}

#pragma mark 眼睛(左上)

-(void)drawEye2:(CGContextRef) context{

    

    CGContextAddArc(context, 162, 160, 10, 0,- M_PI, 1);

    CGContextFillPath(context);

    

}

#pragma mark 眼睛(右下)

-(void)drawEye3:(CGContextRef) context{

    

    CGContextAddArc(context, 212, 160, 10, 0,- M_PI, 0);

    CGContextSetLineWidth(context, 3);

    CGContextFillPath(context);

    

}

#pragma mark 眼睛(右上)

-(void)drawEye4:(CGContextRef) context{

    

    CGContextAddArc(context, 212, 160, 10, 0,- M_PI, 1);

    CGContextSetLineWidth(context, 3);

    CGContextFillPath(context);

    

}

#pragma mark 眼睛连线

- (void)drawEyeLine :(CGContextRef) context{

    

    //移动到某一点

    CGContextMoveToPoint(context, 162, 160);

    //添加一条线

    CGContextAddLineToPoint(context, 212, 160);

    CGContextSetLineWidth(context, 3);//线宽

    //    3.绘制图形

    CGContextStrokePath(context);

    

}

#pragma mark  身体(左) 贝塞尔

- (void)drawBody:(CGContextRef) context{

    

    CGPoint p1=CGPointMake(152, 185);

    CGPoint p2=CGPointMake(20, 290);

    CGPoint p3=CGPointMake(120, 400);

    

    CGContextMoveToPoint(context, p1.x, p1.y);

    

    CGContextAddQuadCurveToPoint(context, p2.x, p2.y, p3.x, p3.y);

    

    CGContextStrokePath(context);

}

#pragma mark  身体(右)贝塞尔

- (void)drawBody2:(CGContextRef) context{

    

    CGPoint p1=CGPointMake(222, 185);

    CGPoint p2=CGPointMake(355, 290);

    CGPoint p3=CGPointMake(255, 400);

    

    CGContextMoveToPoint(context, p1.x, p1.y);

    

    CGContextAddQuadCurveToPoint(context, p2.x, p2.y, p3.x, p3.y);

    

    CGContextStrokePath(context);

}

#pragma mark  身体(下)贝塞尔

- (void)drawBody3:(CGContextRef) context{

    

    CGPoint p1=CGPointMake(120, 400);//第一个点

    CGPoint p2=CGPointMake(187.5, 450);//中间的点

    CGPoint p3=CGPointMake(255, 400);//第二个点

    

    CGContextMoveToPoint(context, p1.x, p1.y);

    

    CGContextAddQuadCurveToPoint(context, p2.x, p2.y, p3.x, p3.y);

    

    CGContextStrokePath(context);

}

#pragma mark  身体(左胳膊) 贝塞尔

- (void)drawBody4:(CGContextRef) context{

    

    CGPoint p1=CGPointMake(148, 180);

    CGPoint p2=CGPointMake(0, 300);

    CGPoint p3=CGPointMake(103, 380);

    

    CGContextMoveToPoint(context, p1.x, p1.y);

    

    CGContextAddQuadCurveToPoint(context, p2.x, p2.y, p3.x, p3.y);

    

    CGContextStrokePath(context);

}

#pragma mark  身体(右胳膊)贝塞尔

- (void)drawBody5:(CGContextRef) context{

    

    CGPoint p1=CGPointMake(226, 180);

    CGPoint p2=CGPointMake(375, 300);

    CGPoint p3=CGPointMake(272, 380);

    

    CGContextMoveToPoint(context, p1.x, p1.y);

    

    CGContextAddQuadCurveToPoint(context, p2.x, p2.y, p3.x, p3.y);

    

    CGContextStrokePath(context);

}

#pragma mark 脚(左)贝塞尔

- (void)drawBody6:(CGContextRef) context{

    

    CGPoint p1=CGPointMake(120, 400);

    CGPoint p2=CGPointMake(140, 450);

    CGPoint p3=CGPointMake(175, 424);

    

    CGContextMoveToPoint(context, p1.x, p1.y);

    

    CGContextAddQuadCurveToPoint(context, p2.x, p2.y, p3.x, p3.y);

    

    CGContextStrokePath(context);

}

#pragma mark 脚(左)贝塞尔

- (void)drawBody7:(CGContextRef) context{

    

    CGPoint p1=CGPointMake(255, 400);

    CGPoint p2=CGPointMake(234, 450);

    CGPoint p3=CGPointMake(199, 424);

    

    CGContextMoveToPoint(context, p1.x, p1.y);

    

    CGContextAddQuadCurveToPoint(context, p2.x, p2.y, p3.x, p3.y);

    

    CGContextStrokePath(context);

}

@end

原谅小菜鸟见得世面少,不过,真的有认真地写了代码,请喜欢大白的童鞋,拿去试试吧,大白送给你们。

今天学习很开心,明天继续加油,大家一起加油哟~~

原文地址:https://www.cnblogs.com/wenqingdan-1207/p/4767892.html