iOS画图

1.直线

//1.获取上下文

    CGContextRef ctx = UIGraphicsGetCurrentContext();

    

    //1.1 设置线条的宽度

    CGContextSetLineWidth(ctx, 66);

    //1.2 设置线条的起始点样式

    CGContextSetLineCap(ctx,kCGLineCapButt);

    //1.3  虚实切换 ,实线5虚线10

    CGFloat length[] = {3,3};

    CGContextSetLineDash(ctx, 0, length, 0);

    //1.4 设置颜色

    [[UIColor whiteColor]set];

    //2.设置路径-起点

    CGContextMoveToPoint(ctx, 0, 0);

    //终点

    CGContextAddLineToPoint(ctx, WIDTH/2, WIDTH/2);

    

2.圆

//1.获取上下文

    CGContextRef ctx = UIGraphicsGetCurrentContext();

    

    //1.1 设置线条的宽度

    CGContextSetLineWidth(ctx, 6);

    //1.2 设置线条的起始点样式

    CGContextSetLineCap(ctx,kCGLineCapButt);

    //1.3  虚实切换 ,实线5虚线10

    CGFloat length[] = {3,6};

    CGContextSetLineDash(ctx, 0, length, 2);

    //1.4 设置颜色

    [[UIColor whiteColor]set];

    //[[UIColor colorWithRed:255/255 green:255/255 blue:255/255 alpha:76/255] set];

    //2.设置路径

    CGContextAddArc(ctx, kScreenW/2 , kScreenW/2, kScreenW/2-10, -M_PI_2*3, M_PI_2, 0);

    //之前版

    //CGContextAddArc(ctx, 200/2 , 200/2, 80, -5*M_PI_4, M_PI_4, 0);

    //3.绘制

    CGContextStrokePath(ctx);

3。实线圆

 //绘制内部的进度条

    //1.获取上下文

    CGContextRef ctx1 = UIGraphicsGetCurrentContext();

    

    //1.1 设置线条的宽度

    CGContextSetLineWidth(ctx1, 2);

    //1.2 设置线条的起始点样式

    CGContextSetLineCap(ctx1,kCGLineCapButt);

    //1.3  虚实切换 ,实线5虚线10

    CGFloat length1[] = {3,3};

    CGContextSetLineDash(ctx1, 0, length1, 0);

    //74bf6f  a2ef9d

    [UIColor colorWithRed:252/255 green:212/255 blue:117/255 alpha:255/255];

    //1.4 设置颜色------该颜色是进度条绘制时的颜色

    [[UIColor colorWithRed:252.0/255 green:212.0/255 blue:117.0/255 alpha:1] set];

    // [[UIColor greenColor]set];

    

    //2.设置路径

    

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(numberChange:) name:@"number" object:nil];

    CGFloat end1 = -M_PI_2*3+(2*M_PI*_num/100);

    //之前版

    //CGFloat end = -5*M_PI_4+(6*M_PI_4*_num/100);

    //0表示顺时针

    CGContextAddArc(ctx1, kScreenW/2 , kScreenW/2, kScreenW/2-20, -M_PI_2*3, end1 , 0);

    //之前版

    //CGContextAddArc(ctx, 200/2 , 200/2, 80, -5*M_PI_4, end , 0);

    

    //3.绘制

    CGContextStrokePath(ctx1);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值