iOS UIBezierPath曲線 貝塞爾曲線 二

運行如下:

未調用closePath
調用closePath

2、畫矩形

UIColor*color=[UIColor redColor];

[color set];//設置線條顏色

UIBezierPath*bezierPath=[UIBezierPath bezierPathWithRect:CGRectMake(20,20,100,50)];

bezierPath.lineWidth=3.0;

bezierPath.lineCapStyle=kCGLineCapSquare;//線條拐角

bezierPath.lineJoinStyle=kCGLineJoinBevel;//終點處理

[bezierPath stroke];

運行如下:

3、畫橢圓

//UIColor*stroke=[UIColor redColor];//設置紅色畫筆線

//[stroke set];//填充顏色

//UIBezierPath*bezierPath=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(60,60,50,40)];

//[bezierPath fill];

//[bezierPath stroke];//fill和stroke的區別:fill是用線連接并填充stroke就是用線連接不填充

運行如下:

fill


stroke

4、畫弧線

UIColor*color=[UIColor redColor];

[color set];//設置線條顏色

UIBezierPath*bezierPath=[UIBezierPath bezierPathWithArcCenter:CGPointMake(100,100) radius:40 startAngle:M_PI_4 endAngle:M_PI clockwise:YES];

bezierPath.lineWidth=5.0;

bezierPath.lineCapStyle=kCGLineCapRound;

bezierPath.lineJoinStyle=kCGLineJoinRound;

[bezierPath stroke];

運行如下:

5、畫弧線---有一個控制點,如下圖:

一個控制點

UIColor*color=[UIColor redColor];

[color set];

UIBezierPath*bezierPath=[UIBezierPath bezierPath];

bezierPath.lineWidth=3.0;

bezierPath.lineCapStyle=kCGLineCapRound;//線拐角

bezierPath.lineJoinStyle=kCGLineJoinRound;//接點處理

[bezierPath moveToPoint:CGPointMake(10,100)];

[bezierPath addQuadCurveToPoint:CGPointMake(150,100)controlPoint:CGPointMake(85,10)];

[bezierPath stroke];

運行如下:

一個控制點

6、畫弧線-兩個控制點,如下圖:

兩個控制點

UIColor*color=[UIColor redColor];

[color set];

UIBezierPath*bezierPath=[UIBezierPath bezierPath];

bezierPath.lineWidth=3.0;

bezierPath.lineCapStyle=kCGLineCapRound;//線條拐角

bezierPath.lineJoinStyle=kCGLineJoinRound;//終點處理

[bezierPath moveToPoint:CGPointMake(10,100)];

[bezierPath addCurveToPoint:CGPointMake(200,100)controlPoint1:CGPointMake(80,20)controlPoint2:CGPointMake(150,150)];

[bezierPath stroke];

運行如下:

兩個控制點
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容