Core Graphics绘图

本文介绍了贝塞尔的简单绘图,画线,三角形,圆形进度条等,

效果图

 

1.通过路径画线

 

-(void)setLineAppenPath{
    //获取上下文
    CGContextRef tx = UIGraphicsGetCurrentContext();
    //获得路径(要记得释放)
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 10, 180);
    CGPathAddLineToPoint(path, NULL, width-10, 180);
    CGContextSetStrokeColorWithColor(tx, [UIColor yellowColor].CGColor);
    CGContextAddPath(tx, path);
    CGContextSetLineWidth(tx, 10);
    //添加一个圆
    CGMutablePathRef path1= CGPathCreateMutable();
    //CGPathAddRoundedRect(path, NULL, CGRectMake(100, 180, 100, 100), 50, 50);
    CGPathAddEllipseInRect(path1, NULL, CGRectMake(100, 130, 100, 100));
    CGContextAddPath(tx, path1);

    CGContextStrokePath(tx);
    //释放路径
    CGPathRelease(path);
    CGPathRelease(path1);
}


2.通过节点画三角形

 

 

-(void)threeAngle{
    CGContextRef tx = UIGraphicsGetCurrentContext();
    CGContextMoveToPoint(tx, 10, 80);
    CGContextAddLineToPoint(tx, width-10, 80);
    
    CGContextSetShadowWithColor(tx, CGSizeMake(10, 10), 10, [UIColor blackColor].CGColor);
    CGContextStrokePath(tx);
    
    CGContextMoveToPoint(tx, 10, 80);
    //设置终点
    CGContextAddLineToPoint(tx, width-10, 300);
    //渲染
    CGContextStrokePath(tx);
    
    
    CGContextMoveToPoint(tx, width-10, 300);
    //设置终点
    CGContextAddLineToPoint(tx, width-10, 80);
    //渲染
    CGContextStrokePath(tx);
}


3.圆形进度条

 

 

-(void)roundAngle{
    CGContextRef tx1 = UIGraphicsGetCurrentContext();
    CGContextAddArc(tx1, width/2, height/2, 80,  -M_PI_2, M_PI*2, 0);
    [[UIColor lightGrayColor] set];
    CGContextSetLineWidth(tx1, 5);
    CGContextStrokePath(tx1);
    //画弧
    CGContextRef tx = UIGraphicsGetCurrentContext();
    CGContextAddArc(tx, width/2, height/2, 80,  -M_PI_2, -M_PI_2+M_PI*self.data/180, 0);
    [[UIColor whiteColor] set];
    CGContextSetLineWidth(tx, 5);
    CGContextStrokePath(tx);
}


源码地址:点击打开链接

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值