iOS[UIKit框架]UIBezierPath篇(1)
今天主要看下UIBezierPath.h中的基本属性
==============================
1、实例方法:
+ (instancetype)bezierPath;
+ (instancetype)bezierPathWithRect:(CGRect)rect;
+ (instancetype)bezierPathWithOvalInRect:(CGRect)rect;
+ (instancetype)bezierPathWithRoundedRect:(CGRect)rect cornerRadius:(CGFloat)cornerRadius; // rounds all corners with the same horizontal and vertical radius
/*
UIRectCorner 类型的取值
typedef NS_OPTIONS(NSUInteger, UIRectCorner) {
UIRectCornerTopLeft = 1 << 0,
UIRectCornerTopRight = 1 << 1,
UIRectCornerBottomLeft = 1 << 2,
UIRectCornerBottomRight = 1 << 3,
UIRectCornerAllCorners = ~0UL
};
*/
+ (instancetype)bezierPathWithRoundedRect:(CGRect)rect byRoundingCorners:(UIRectCorner)corners cornerRadii:(CGSize)cornerRadii;
+ (instancetype)bezierPathWithArcCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise;
+ (instancetype)bezierPathWithCGPath:(CGPathRef)CGPath;
- (instancetype)init NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
2、CGPath属性及方法
@property(nonatomic) CGPathRef CGPath;
- (CGPathRef)CGPath NS_RETURNS_INNER_POINTER CF_RETURNS_NOT_RETAINED;
3、设置path的起点
- (void)moveToPoint:(CGPoint)point;
4、在点point和起点之间加一条线
-(void)addLineToPoint:(CGPoint)point;
5、在点endPoint和起点之间添加一条控制点为controlPoint1,controlPoint2的三次贝塞尔曲线
- (void)addCurveToPoint:(CGPoint)endPoint controlPoint1:(CGPoint)controlPoint1 controlPoint2:(CGPoint)controlPoint2;
作用效果如图:
799670-20151013172626304-936217179.png
6、在点endPoint和起点之间添加一条控制点为controlPoint的二次贝塞尔曲线
- (void)addQuadCurveToPoint:(CGPoint)endPoint controlPoint:(CGPoint)controlPoint;
作用效果如图:
799670-20151013173704351-1059522850-2.png
7、画一条以center为中心,半径是radius,开始的角度是startAngle,终止的角度是endAngle的圆弧,clockwise表示是否顺时针
- (void)addArcWithCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise NS_AVAILABLE_IOS(4_0);
下图为弧线的参考系:
45aafdc6-0044-38fd-a645-7ddf4684e3f5.jpeg
8、封闭Path(即连接起点和终点)
- (void)closePath;
9、去掉所有点,此时Path便没有了
- (void)removeAllPoints;
10、添加路径
-(void)appendPath:(UIBezierPath *)bezierPath;
11、修改路径(这个方法似乎只是获取了和Path一样的路径Path1)
- (UIBezierPath *)bezierPathByReversingPath NS_AVAILABLE_IOS(6_0);
12、旋转
- (void)applyTransform:(CGAffineTransform)transform
13、path是否为空
@property(readonly,getter=isEmpty) BOOL empty;
14、获取path的矩形边界
@property(nonatomic,readonly) CGRect bounds;
15、获取当前的点
@property(nonatomic,readonly) CGPoint currentPoint;
16、路径是否包含点point
- (BOOL)containsPoint:(CGPoint)point;
17、线条宽度
@property(nonatomic) CGFloat lineWidth;
18、线头的帽子类型,有三种类型平的(kCGLineCapButt),方的(kCGLineCapSquare),圆角的(kCGLineCapRound)
@property(nonatomic) CGLineCap lineCapStyle;
效果如下图:
0B9F91BA-BBC3-4ECC-8B27-1A22927EEF9D.png
19、连接点的样式,即拐点的样式,同样有三种,尖的(kCGLineJoinMiter),平的(kCGLineJoinBevel),圆角的(kCGLineJoinRound)
@property(nonatomic) CGLineJoin lineJoinStyle;
效果如下图:
4BAF1054-C1A7-4FE3-B68A-88ABB26E8736.png
20、当连接点的样式是kCGLineJoinMiter时的斜接程度限制,也就是尖角程度的限制,如果斜接的时候超过这个值,就在之间添加一个斜边。
@property(nonatomic) CGFloat miterLimit;
21、曲线的平滑程度,值越小越平滑越费时,值越大会产生锯齿
@property(nonatomic) CGFloat flatness;
22、
@property(nonatomic) BOOL usesEvenOddFillRule;
23、设置线型
- (void)setLineDash:(nullable const CGFloat *)pattern count:(NSInteger)count phase:(CGFloat)phase;
24、检索线型
- (void)getLineDash:(nullable CGFloat *)pattern count:(nullable NSInteger *)count phase:(nullable CGFloat *)phase;
25、填充
- (void)fill;
26、描边
-(void)stroke;
27、用指定的混合模式和透明度值来描绘受接收路径所包围的区域
-(void)fillWithBlendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha;
28、 使用指定的混合模式和透明度值沿着接收器路径。绘制一行
- (void)strokeWithBlendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha;
29、 剪切被接收者路径包围的区域 该路径是带有剪切路径的当前绘图上下文。使得其成为我们当前的剪切路径
- (void)addClip;