1.使用贝塞尔画风车和画梯形的唯一区别就是风车需要曲线。
绘制如图所示的一段弧形,只要有三个标记点坐标即可。1为起点,3为中点,2为控制点
2.绘制之前我们头脑里要有一个风车形状:(我脑中的风车)
我们可以把这个风车分成两个图形的组合,(我是这样分割的,你也可以有其他多种分割方法)
3.开始绘制吧:
- (void)drawRect:(CGRect)rect{
//设置颜色
UIColor *color = [UIColor redColor];
[color set];
//初始化贝塞尔,绘制上半个风车
UIBezierPath *mPath = [[UIBezierPath alloc] init];
mPath.lineWidth = 5;//线条宽度
mPath.lineCapStyle = kCGLineCapRound;//拐角
mPath.lineJoinStyle = kCGLineCapRound;//终点
[mPath moveToPoint:CGPointMake(50, 200)];//起点
[mPath addQuadCurveToPoint:CGPointMake(150, 200) controlPoint:CGPointMake(100, 100)];//前一个参数是终点,后一个参数是控制点
[mPath addQuadCurveToPoint:CGPointMake(250, 200) controlPoint:CGPointMake(200, 300)];
[mPath fill];//填充色
//绘制下半个风车
UIBezierPath *nPath = [[UIBezierPath alloc] init];
nPath.lineWidth = 5;
nPath.lineCapStyle = kCGLineCapRound;
nPath.lineJoinStyle = kCGLineCapRound;
[nPath moveToPoint:CGPointMake(150, 100)];
[nPath addQuadCurveToPoint:CGPointMake(150, 200) controlPoint:CGPointMake(250, 150)];
[nPath addQuadCurveToPoint:CGPointMake(150, 300) controlPoint:CGPointMake(50, 250)];
[nPath closePath];//闭合
[nPath stroke];//边框填充
}