关于过已知点画平滑曲线,这里有一篇比较好理解的博客http://blog.csdn.net/microchenhong/article/details/6316332
需求是:给定一组数据,将其用平滑曲线描绘出来,画成一个曲线统计图。
我这里直接将数据根据公司需求换成了一个存放“CGPoint”的数组,直接上代码:
//根据points中的点画出曲线
- (void)drawCurveChartWithPoints:(NSMutableArray *)points
{
UIBezierPath* path1 = [UIBezierPath bezierPath];
[path1 setLineWidth:]; //设置画笔宽度
//遍历各个点,画曲线
for(int i=; i<[points count]-; i++){
CGPoint startPoint = [[points objectAtIndex:i] CGPointValue];
CGPoint endPoint = [[points objectAtIndex:i+] CGPointValue];
[path1 moveToPoint:startPoint];
[UIView animateWithDuration: animations:^(){
[path1 addCurveToPoint:endPoint controlPoint1:CGPointMake((endPoint.x-startPoint.x)/+startPoint.x, startPoint.y) controlPoint2:CGPointMake((endPoint.x-startPoint.x)/+startPoint.x, endPoint.y)];
}];
}
[self.lineColor set]; //设置画笔颜色
path1.lineCapStyle = kCGLineCapRound;
[path1 strokeWithBlendMode:kCGBlendModeNormal alpha:];
}
PS:这是我暂时找到的较好的方法了,如果有更Nice的方法,请给我留言。不胜感激。。。