本文介绍了贝塞尔的简单绘图,画线,三角形,圆形进度条等,
效果图
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);
}
源码地址:点击打开链接