系統(tǒng)的api
+ (instancetype)bezierPath;//初始化貝塞爾曲線(無形狀)
+ (instancetype)bezierPathWithRect:(CGRect)rect;//繪制矩形貝塞爾曲線
+ (instancetype)bezierPathWithRoundedRect:(CGRect)rect cornerRadius:(CGFloat)cornerRadius;// 圓角矩形, 每個(gè)角都是圓角
+ (instancetype)bezierPathWithRoundedRect:(CGRect)rect byRoundingCorners:(UIRectCorner)corners cornerRadii:(CGSize)cornerRadii;//矩形圓角設(shè)置, 可以選擇哪個(gè)角設(shè)置成圓角, 以及設(shè)置圓角的尺寸
+ (instancetype)bezierPathWithArcCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise;//圓弧設(shè)置, 終點(diǎn)位置, 半徑, 開始角度, 結(jié)束角度, 一般用M_PI設(shè)置是否是順時(shí)針畫圓弧
- (void)moveToPoint:(CGPoint)point;// 以 point點(diǎn) 開始作為起點(diǎn), 一般用`+ (instancetype)bezierPath`創(chuàng)建的貝塞爾曲線让虐,先用該方法標(biāo)注一個(gè)起點(diǎn),再調(diào)用其他的創(chuàng)建線條的方法來繪制曲線
-(void)addLineToPoint:(CGPoint)point;// 繪制二次貝塞爾曲線的關(guān)鍵方法,即從path的最后一點(diǎn)開始添加一條線到point點(diǎn)- 畫直線-
- (void)addQuadCurveToPoint:(CGPoint)endPoint controlPoint:(CGPoint)controlPoint;// 繪制二次貝塞爾曲線的關(guān)鍵方法,和`-moveToPoint:`配合使用. endPoint為終止點(diǎn),controlPoint為控制點(diǎn).
- (void)addCurveToPoint:(CGPoint)endPoint controlPoint1:(CGPoint)controlPoint1 controlPoint2:(CGPoint)controlPoint2;// 繪制三次貝塞爾曲線的關(guān)鍵方法,以三個(gè)點(diǎn)畫一段曲線. 一般和moveToPoint:配合使用.// 其中,起始點(diǎn)由`-moveToPoint:`設(shè)置,終止點(diǎn)位為`endPoint:`, 控制點(diǎn)1的坐標(biāo)controlPoint1,控制點(diǎn)2的坐標(biāo)是controlPoint2.
- (void)addArcWithCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise;// 繪制一段圓弧, center:原點(diǎn)坐標(biāo),radius:半徑,startAngle:起始角度,endAngle:終止角度,clockwise順時(shí)針/逆時(shí)針方向繪制
- (void)closePath;// 閉合線
- (void)removeAllPoints;// 移除所有的點(diǎn),從而有效地刪除所有子路徑
- (void)appendPath:(UIBezierPath*)bezierPath;// 追加指定的bezierPath到路徑上
- (void)applyTransform:(CGAffineTransform)transform;// 用仿射變換矩陣變換路徑的所有點(diǎn)
- (void)fillWithBlendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha;// 填充路徑- (void)fill;// 各個(gè)點(diǎn)連線- (void)stroke;// 填充模式, alpha 設(shè)置// blendMode :?
- (void)strokeWithBlendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha;// 鏈接模式, alpha 設(shè)置
- (void)addClip;// 圖形繪制超出當(dāng)前路徑范圍,則不可見
畫虛線
// 9. 繪制豎直虛線
UIBezierPath*verticalLinePath = [UIBezierPath bezierPath];
CGFloatdash[] = {3.0,3.0};//第一個(gè)參數(shù)是線條長度, 第二個(gè)是間距, 如果是直線就設(shè)置為nil
?[verticalLinePath setLineDash:dash count:2phase:0.0];// 畫虛線
?[verticalLinePath moveToPoint:CGPointMake(5,0)]; // 起始點(diǎn)
?[verticalLinePath addLineToPoint:CGPointMake(5, ScreenHeight*2)];//終點(diǎn)
?[verticalLinePath stroke];// 繪制
?[verticalLinePath fill];// 填充
填充色設(shè)置---------一定要先定點(diǎn)再填充不然會(huì)設(shè)置失敗系統(tǒng)找不到給誰填充
[[UIColor grayColor] setStroke];// 設(shè)置邊框顏色---
[[UIColor yellowColor] setfill];// 設(shè)置填充色
UIBezierPath 常用設(shè)置
1.CGPath: 將UIBezierPath類轉(zhuǎn)換成CGPath
2.currentPoint: 當(dāng)前path的位置罢荡,可以理解為path的終點(diǎn)
3.lineWidth: 線條寬度
4.lineCapStyle: 端點(diǎn)樣式
5.lineJoinStyle: 連接類型
6.flatness: 繪線的精細(xì)程度赡突,默認(rèn)為0.6,數(shù)值越大区赵,需要處理的時(shí)間越長
7.usesEvenOddFillRule: 判斷奇偶數(shù)組的規(guī)則繪制圖像,圖形復(fù)雜時(shí)填充顏色的一種規(guī)則惭缰。類似棋盤
8.miterLimit: 最大斜接長度(只有在使用kCGLineJoinMiter是才有效,最大限制為10), 邊角的角度越小笼才,斜接長度就會(huì)越大漱受,為了避免斜接長度過長,使用lineLimit屬性限制骡送,如果斜接長度超過miterLimit昂羡,邊角就會(huì)以KCALineJoinBevel類型來顯示
9.- setLineDash:count:phase:為path繪制虛線絮记,dash數(shù)組存放各段虛線的長度,count是數(shù)組元素?cái)?shù)量虐先,phase是起始位置