UIBezierPath的学习


//  CustomView.m
//  贝塞尔曲线的学习
//
//  Created by SeaDrogan on 16/8/21.
//  Copyright © 2016年 SeaDrogan. All rights reserved.
//

#import "CustomView.h"

#import <QuartzCore/QuartzCore.h>

#define   kDegreesToRadians(degrees)  ((pi * degrees)/ 180)

@implementation CustomView

- (void)drawRect:(CGRect)rect {
    
//使用UIBezierPath 画图的步奏
    //1,创建一个UIBezierPath对象
    //2,调用-moveToPoint:设置初始线段的起点
    //3.添加线或者曲线去定义一个获取多个子路径
    //4,改变UIBezierPath对象跟绘图相关的属性,如,我们可以设置画笔的属性,填充样式等
    
    /************ 实例化方法 *************/
    //1--> 这个使用的比较多,因为这个是工程模式创建的对象,我们可以根据我们的需要,任意定制样式,可以画任何我们想画得图像
    //UIBezierPath *path = [UIBezierPath bezierPath];
    
    //2-->这个工厂方法根据一个矩形画出贝塞尔曲线
    //UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(100, 100, 200, 200)];
    
    //3-->这个工厂方法根据一个矩形画内切曲线,通常用它来画圆或者椭圆
    //UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(100, 100, 200, 200)];
    
    //4--> 这个工厂方法是画矩形的,但是这个矩形是可以画圆角的,第一个参数是矩形,第二个参数是圆角的大小,
    //UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(100, 100, 200, 200) cornerRadius:10];
    
    //5--> 这个工厂方法跟第四个是一样的,但是可以根据某一角化成圆角, 第一个参数是矩形,第二个参数是指定的圆角的位置,第三个是圆角的大小
    //UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(100, 100, 200, 200)\
                                               byRoundingCorners:UIRectCornerTopLeft\
                                                     cornerRadii:CGSizeMake(10, 10)];
    
    //6 --> 这个工厂方法是画圆弧,参数说明,center:弧线中心点的坐标 radius:弧线所在远的半径,startAngle:弧线的开始角度 endAngle:弧线结束的角度 clockwise:是否顺时针画弧线
    //UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:[UIApplication sharedApplication].keyWindow.center\
                                                        radius:100\
                                                    startAngle:0\
                                                      endAngle:M_PI*2\
                                                     clockwise:YES];
    
    //画矩形
//    UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(60, 50, 300, 300)];
//    
//    path.lineWidth = 5.f;
//    [[UIColor redColor] set];
//    
//    [path closePath];
//    
//    [path stroke];
   
    //画三角
//    UIBezierPath *path = [UIBezierPath bezierPath];
//    
//    [path moveToPoint:CGPointMake(100, 100)];
//    [path addLineToPoint:CGPointMake(350, 100)];
//    [path addLineToPoint:CGPointMake(225, 350)];
//    
//    [path closePath];//封闭接口
//    
//    [[UIColor redColor] set];
//    
//    [path fill];
//    [path stroke];
    
    //lineCapStyle 属性是用来设置线条拐角帽样式的,有三种样式
//    typedef CF_ENUM(int32_t, CGLineCap) {
//        kCGLineCapButt,// 默认样式
//        kCGLineCapRound,//圆角
//        kCGLineCapSquare//正方形
//    };
    
    //lineJoinStyle 属性是用来设置两条线条连接的样式,也是有三种样式
//    typedef CF_ENUM(int32_t, CGLineJoin) {
//        kCGLineJoinMiter,//斜角
//        kCGLineJoinRound,//圆滑衔接
//        kCGLineJoinBevel//斜角连接
//    };
    
    //画圆 (参数为正方形则为正圆)
//    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(60, 50, 300, 300)];
//    
//    //进行颜色填充
//    [[UIColor blueColor] set];
//    [path fill];
//    
//    //设置画笔参数
//    path.lineWidth = 5.0f;
//    [[UIColor redColor] set];
//    
//    [path stroke];
    
    //画椭圆 (参数不为正圆则为椭圆)
//    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(60, 50, 200, 300)];
//    
//    [[UIColor redColor] set];
//    [path fill];
//    
//    [[UIColor yellowColor] set];
//    path.lineWidth = 5.f;
//    [path stroke];
    
    //画圆角的矩形(方法一)
//    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(60, 50, 300, 300) cornerRadius:10];
//    
//    path.lineWidth = 5.f;
//    
//    [[UIColor redColor] set];
//    
//    [path stroke];
    
//    //方法二 (可通过RoundingCorners 参数来设置圆角的位置)radii 参数来指定水平和垂直方向的半径大小
//    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(60, 50, 300, 300)
//                                               byRoundingCorners:UIRectCornerTopLeft   |
//                                                                 UIRectCornerTopRight  |
//                                                                 UIRectCornerBottomLeft|
//                                                                 UIRectCornerBottomRight
//                                                     cornerRadii:CGSizeMake(10, 10)];
//    
//    [[UIColor redColor] set];
//    
//    path.lineWidth = 5.f;
//    
//    
//    [path stroke];
    
    
    //画弧
//    const CGFloat pi = 3.14159265359;
//    
//    CGPoint center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
//    
//    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center
//                                                        radius:100
//                                                    startAngle:0
//                                                      endAngle:kDegreesToRadians(90)
//                                                     clockwise:NO];
//    
//    path.lineWidth = 5.f;
//    [[UIColor redColor] set];
//    
//    path.lineCapStyle = kCGLineCapRound;
//    
//    [path stroke];
    
    //画二次贝塞尔曲线 ToPoint:终端点  controlPoint:控制点
    //[path addQuadCurveToPoint:CGPointZero controlPoint:CGPointZero];
    
    //步骤:1.先设置一个起始点,也是通过,moveToPoint:设置
    //2.调用: addQuadCurveToPoint:controlPoint: 方法设置终点和控制点
//    
//    //首先设置一个起始点
//    UIBezierPath *path = [UIBezierPath bezierPath];
//    
//    [path moveToPoint:CGPointMake(20, self.frame.size.height - 100)];
//    
//    //添加二次曲线
//    [path addQuadCurveToPoint:CGPointMake(self.frame.size.width - 20,
//                                          self.frame.size.height - 100)
//                 controlPoint:CGPointMake(self.frame.size.width / 2, 0)];
//    
//    path.lineWidth = 2.5f;
//    [[UIColor redColor] set];
//    
//    [path stroke];
}

@end


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值