直接上代码:
UIBezierPath * bPath = [[UIBezierPath alloc]init];
[bPath setLineCapStyle:kCGLineCapRound];
[bPath setLineJoinStyle:kCGLineJoinRound];
[bPath setLineWidth:3.];
[[UIColor redColor]setStroke];
for (int i=0; i < line.points.count; i++) {
CGPoint p = [line.points[i] CGPointValue];
if (i==0) {
//3.把画笔移动到某一个点
[bPath moveToPoint:p];
}else{
//4.添加一条线到某一个点
CGPoint prePoint = [line.points[i-1] CGPointValue];
CGPoint midP = [self calculateMidPointForPoint:p andPoint:prePoint];
[bPath addQuadCurveToPoint:midP controlPoint:prePoint];
}
}
[bPath stroke];
<pre name="code" class="objc">- (CGPoint)calculateMidPointForPoint:(CGPoint)p1 andPoint:(CGPoint)p2 {
return CGPointMake((p1.x + p2.x) / 2.0, (p1.y + p2.y) / 2.0);
}