iOS UIBezierPath 貝塞爾曲線

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

//創(chuàng)建貝塞爾曲線
UIBezierPath *mPath = [UIBezierPath bezierPath];
[mPath moveToPoint:CGPointMake(100, 100)]; //創(chuàng)建一個(gè)點(diǎn)
[mPath addLineToPoint:CGPointMake(100, 300)]; // 加條線,從點(diǎn)移動(dòng)到另一個(gè)點(diǎn)
[mPath addLineToPoint:CGPointMake(300, 300)]; // 加條線,從點(diǎn)移動(dòng)到另一個(gè)點(diǎn)
[mPath closePath]; // 關(guān)閉貝塞爾線

UIColor *fillColor = [UIColor greenColor];          //設(shè)置顏色
[fillColor set];                                    //填充顏色
[mPath fill];                                       //貝塞爾線進(jìn)行填充

UIColor *stroke = [UIColor redColor];               //設(shè)置紅色畫筆線
[stroke set];                                       //填充顏色
[mPath stroke];                                     //貝塞爾線進(jìn)行畫筆填充

//創(chuàng)建一個(gè)橢圓的貝塞爾曲線 半徑相等 就是圓了
UIBezierPath *mPath1 = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(60, 60, 10, 10)];
[mPath1 fill];

//創(chuàng)建一個(gè)矩形的貝塞爾線
UIBezierPath *mPath2 = [UIBezierPath bezierPathWithRect:CGRectMake(70,70, 10, 10)];
[mPath2 stroke];

//創(chuàng)建一個(gè)圓弧 傳的弧度
UIBezierPath *mPath3 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(50, 100)
                                                      radius:10
                                                  startAngle:DEGREES_TO_RADIANS(0)
                                                    endAngle:DEGREES_TO_RADIANS(180)
                                                   clockwise:YES];
[mPath3 fill];

//創(chuàng)建一個(gè) 矩形的貝塞爾曲線, 帶圓角
UIBezierPath *mPath4 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(250, 15, 20, 20) cornerRadius:3];
[mPath4 fill];

//定義一個(gè)矩形 邊角會(huì)變成 設(shè)置的角度  方位/角度大小
UIBezierPath *mPath5 =[UIBezierPath bezierPathWithRoundedRect:CGRectMake(250, 45, 40, 40)
                                            byRoundingCorners:UIRectCornerTopLeft
                                                  cornerRadii:CGSizeMake(10, 10)];
[mPath5 fill];


//定義一個(gè)二級(jí)的賽貝爾曲線 重點(diǎn)|拐彎點(diǎn)
UIBezierPath *mPath6 = [UIBezierPath bezierPath];
[mPath6 moveToPoint:CGPointMake(10,260)];
[mPath6 addQuadCurveToPoint:CGPointMake(200,260) controlPoint:CGPointMake(85, 240)];
[mPath6 setLineWidth:3];
[mPath6 stroke];

//定義一個(gè)三級(jí)的賽貝爾曲線 終點(diǎn)|拐點(diǎn)1|拐點(diǎn)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];

//當(dāng)前貝塞爾的點(diǎn)
NSLog(@"mPath7 currentPoint is  : %@",NSStringFromCGPoint(mPath7.currentPoint));
Simulator Screen Shot 2016年4月14日 下午1.30.09.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容