首页投稿(暂停使用,暂停投稿)

UIBezierPath

2016-07-28  本文已影响0人  任性不认命ToT

一、UIBezierPath的介绍


UIBezierPath主要用来绘制矢量图形,它是基于Core GraphicsCGPathRef数据类型和path绘图属性的一个封装,所以是需要图形上下文的CGContextRef,所以一般UIBezierPathdrawRect中使用。


二、UIBezierPath 的常用属性

以下属性是给已存在的path设置路径属性,如宽度,边角类型,拐角类型等


三、UIBezierPath构建方法

以下类方法是创建一条path

/** 仅仅初始化,需要用实例方法添加线 */
+ (instancetype)bezierPath;  
/** 获得矩形path */  
+ (instancetype)bezierPathWithRect:(CGRect)rect;
/** 获得圆形或椭圆path */
+ (instancetype)bezierPathWithOvalInRect:(CGRect)rect;
/** 获得圆角矩形path,四周均圆角,想要某个角或者某些角圆角用下面的方法 */
+ (instancetype)bezierPathWithRoundedRect:(CGRect)rect
                             cornerRadius:(CGFloat)cornerRadius;
/** 获得圆角矩形,是某些角圆角,UIRectCorner是枚举类型 */
+ (instancetype)bezierPathWithRoundedRect:(CGRect)rect
                        byRoundingCorners:(UIRectCorner)corners 
                              cornerRadii:(CGSize)cornerRadii;
/** 获得圆弧形path */
+ (instancetype)bezierPathWithArcCenter:(CGPoint)center       // 圆心
                                 radius:(CGFloat)radius       // 半径
                             startAngle:(CGFloat)startAngle   // 起始角
                               endAngle:(CGFloat)endAngle     // 结束角
                              clockwise:(BOOL)clockwise;      // 是否顺时针
/** 用一条CGPath初始化 */
+ (instancetype)bezierPathWithCGPath:(CGPathRef)CGPath;

四、UIBezierPath实例方法

以下实例方法是给已创建的path添加路径

/** 以某一点开始作为起点,一般用`+ (instancetype)bezierPath`创建的贝塞尔曲线,先用该方法标注一个起点,并调用其他的创建线条的方法来绘制曲线 */
- (void)moveToPoint:(CGPoint)point;
/** 从path的最后一点开始绘制一条线到目标点 */
- (void)addLineToPoint:(CGPoint)point;
/** 添加一条三次贝塞尔曲线 */
- (void)addCurveToPoint:(CGPoint)endPoint
          controlPoint1:(CGPoint)controlPoint1
          controlPoint2:(CGPoint)controlPoint2;
/** 添加一条二次贝塞尔曲线 */   
 - (void)addQuadCurveToPoint:(CGPoint)endPoint
                controlPoint:(CGPoint)controlPoint;
/** 添加一条圆弧,属性定义和类方法中相同 */
- (void)addArcWithCenter:(CGPoint)center 
                  radius:(CGFloat)radius 
              startAngle:(CGFloat)startAngle 
                endAngle:(CGFloat)endAngle
               clockwise:(BOOL)clockwise NS_AVAILABLE_IOS(4_0);
/** 为path添加虚线,pattern数组存放各段虚线的长度,count是数组元素数量,phase是起始位置 */
- (void)setLineDash:(nullable const CGFloat *)pattern 
              count:(NSInteger)count
              phase:(CGFloat)phase;

五、使用


上一篇 下一篇

猜你喜欢

热点阅读