iOS-贝塞尔连续曲线

一个曲线

UIColor *color = [UIColor redColor];
[color set];
UIBezierPath *path = [UIBezierPath bezierPath];
///线的宽度【粗细】
path.lineWidth = ;
///端点类型
path.lineCapStyle = kCGLineCapRound;
///衔接类型
path.lineJoinStyle = kCGLineJoinRound;
///起点
[path moveToPoint:CGPointMake(, )];
[path addCurveToPoint:CGPointMake(, ) controlPoint1:CGPointMake(, ) controlPoint2:CGPointMake(, )];
[path stroke];

图例:

iOS-贝塞尔连续曲线

多个曲线

/**
贝塞尔曲线
CGRect
*/
- (void)draweBezierCurves:(CGRect)rect{
///曲线水平位置y坐标
CGFloat lintY = rect.origin.y;
///每个曲线的水平长度【两个弧度为一个曲线】
NSInteger lineWidth = ;
///每个曲线的上下顶点与水平位置 距离
CGFloat lingPeak = ;
///波浪线个数
NSInteger lineCount = (int)(rect.size.width / lineWidth);
///除了整数外,最后一条线的长度【小于 lineWidth】
CGFloat lastLineWidth = rect.size.width - lineCount*lineWidth;
///贝塞尔
UIBezierPath *path = [UIBezierPath bezierPath];
///线的宽度【粗细】
path.lineWidth = ;
///端点类型
path.lineCapStyle = kCGLineCapRound;
///衔接类型
path.lineJoinStyle = kCGLineJoinRound;
///颜色
UIColor *color = [UIColor redColor]; [color set];
for (int i = ; i < lineCount; i ++) {
///起点
[path moveToPoint:CGPointMake(rect.origin.x + i*lineWidth, lintY)];
///三点成线
[path addCurveToPoint:CGPointMake(rect.origin.x + i*lineWidth + lineWidth, lintY) controlPoint1:CGPointMake(rect.origin.x + i*lineWidth + lineWidth/, lintY - lingPeak) controlPoint2:CGPointMake(rect.origin.x + i*lineWidth + (lineWidth/)*, lintY + lingPeak)];
} if (lastLineWidth > ) {
///起点
[path moveToPoint:CGPointMake(rect.origin.x + lineCount*lineWidth, lintY)];
///三点成线
[path addCurveToPoint:CGPointMake(rect.origin.x + lineCount*lineWidth + lastLineWidth, lintY) controlPoint1:CGPointMake(rect.origin.x + lineCount*lineWidth + lastLineWidth/, lintY - lingPeak) controlPoint2:CGPointMake(rect.origin.x + lineCount*lineWidth + (lastLineWidth/)*, lintY + lingPeak)]; }
[path stroke];
}

图例:

iOS-贝塞尔连续曲线

上一篇:jfinal的ajax例子


下一篇:hdu3535 混合背包