iOS UIBezierPath 贝塞尔曲线

弧度=(角度/180) *PI
角度=(弧度/PI) * 180

//创建贝塞尔曲线
UIBezierPath *mPath = [UIBezierPath bezierPath];
[mPath moveToPoint:CGPointMake(100, 100)]; //创建一个点
[mPath addLineToPoint:CGPointMake(100, 300)]; // 加条线,从点移动到另一个点
[mPath addLineToPoint:CGPointMake(300, 300)]; // 加条线,从点移动到另一个点
[mPath closePath]; // 关闭贝塞尔线

UIColor *fillColor = [UIColor greenColor];          //设置颜色
[fillColor set];                                    //填充颜色
[mPath fill];                                       //贝塞尔线进行填充

UIColor *stroke = [UIColor redColor];               //设置红色画笔线
[stroke set];                                       //填充颜色
[mPath stroke];                                     //贝塞尔线进行画笔填充

//创建一个椭圆的贝塞尔曲线 半径相等 就是圆了
UIBezierPath *mPath1 = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(60, 60, 10, 10)];
[mPath1 fill];

//创建一个矩形的贝塞尔线
UIBezierPath *mPath2 = [UIBezierPath bezierPathWithRect:CGRectMake(70,70, 10, 10)];
[mPath2 stroke];

//创建一个圆弧 传的弧度
UIBezierPath *mPath3 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(50, 100)
                                                      radius:10
                                                  startAngle:DEGREES_TO_RADIANS(0)
                                                    endAngle:DEGREES_TO_RADIANS(180)
                                                   clockwise:YES];
[mPath3 fill];

//创建一个 矩形的贝塞尔曲线, 带圆角
UIBezierPath *mPath4 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(250, 15, 20, 20) cornerRadius:3];
[mPath4 fill];

//定义一个矩形 边角会变成 设置的角度  方位/角度大小
UIBezierPath *mPath5 =[UIBezierPath bezierPathWithRoundedRect:CGRectMake(250, 45, 40, 40)
                                            byRoundingCorners:UIRectCornerTopLeft
                                                  cornerRadii:CGSizeMake(10, 10)];
[mPath5 fill];


//定义一个二级的赛贝尔曲线 重点|拐弯点
UIBezierPath *mPath6 = [UIBezierPath bezierPath];
[mPath6 moveToPoint:CGPointMake(10,260)];
[mPath6 addQuadCurveToPoint:CGPointMake(200,260) controlPoint:CGPointMake(85, 240)];
[mPath6 setLineWidth:3];
[mPath6 stroke];

//定义一个三级的赛贝尔曲线 终点|拐点1|拐点2
UIBezierPath *mPath7 = [UIBezierPath bezierPath];
[mPath7 moveToPoint:CGPointMake(10,290)];
[mPath7 addCurveToPoint:CGPointMake(300, 290)
          controlPoint1:CGPointMake(50, 270)
          controlPoint2:CGPointMake(140, 340)];
[mPath7 stroke];

//当前贝塞尔的点
NSLog(@"mPath7 currentPoint is  : %@",NSStringFromCGPoint(mPath7.currentPoint));
iOS UIBezierPath 贝塞尔曲线_第1张图片
Simulator Screen Shot 2016年4月14日 下午1.30.09.png

你可能感兴趣的:(iOS UIBezierPath 贝塞尔曲线)