UIBezierPath贝塞尔弧线

下面两个网页是我学习时发现的相关的知识网页,总结了常用的知识点。以免忘记,特记录在此。
UIBezierPath贝塞尔弧线常用方法
iOS UIBezierPath类介绍

几点需要注意:绘制的图形要写在drawRect函数里面,在View里面绘制图形。

下面是我熟悉UIBezierPath而写的几个小例子。放在这吧,以后在完善补充。

//
//  XXCycleView.m
//  XXGraphics
//
//  Created by shine on 2016/12/22.
//  Copyright © 2016年 shine. All rights reserved.
//

#import "XXCycleView.h"

@implementation XXCycleView


- (void)drawRect:(CGRect)rect {
    // Drawing code
    //画圆
    //[self setupCycle];
    
    //画三角形
    //[self triAngle];
    
    //画二次贝塞尔曲线
    [self quadCurve];
}

- (void)quadCurve{
    UIBezierPath *path = [UIBezierPath bezierPath];
    
    UIColor *lineColor = [UIColor blackColor];
    [lineColor set]; //设置线条颜色
    
    [path moveToPoint:CGPointMake(100, 100)]; //设置起始点
    
    //绘制二次贝塞尔曲线,第一个参数是结束点 第二个参数是控制点
    [path addQuadCurveToPoint:CGPointMake(200, 100) controlPoint:CGPointMake(150, 50)];
    
    [path stroke];
}
- (void)triAngle{
    
    UIBezierPath *path = [UIBezierPath bezierPath];
    
    [path moveToPoint:self.center];
    
    UIColor *linecolor = [UIColor blackColor];
    CGFloat width = 5;
    [linecolor set];
    
    path.lineWidth = width;
    //第二个点
    CGPoint point2 = CGPointMake(200, 200);
    
    //第三个点
    CGPoint point3 = CGPointMake(300, 300);
    [path addLineToPoint:point2];
    [path addLineToPoint:point3];
   
    [path closePath];
    
    
    [path stroke];
    
}

- (void)setupCycle{
    
    //创建一个路径
    //圆点
    CGPoint cyclePoint = self.center;
    //半径
    CGFloat radius = 100;
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:cyclePoint radius:radius startAngle:0 endAngle:M_PI clockwise:NO];
    
    UIColor *linecolor = [UIColor blackColor];
    path.lineWidth = 5;
    //[linecolor set];
    [linecolor setStroke];
    
    UIColor *fillColor = [UIColor redColor];
    [fillColor setFill];
    
    [path stroke];
    [path fill];
    
}

@end

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