運行如下:
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就是用線連接不填充
運行如下:
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];
運行如下: