UIBezierPath

貝塞爾曲線(xiàn)(UIBezierPath)屬性、方法匯總

UIBezierPath主要用來(lái)繪制矢量圖形,它是基于Core Graphics對(duì)CGPathRef數(shù)據(jù)類(lèi)型和path繪圖屬性的一個(gè)封裝,所以是需要圖形上下文的(CGContextRef),所以一般UIBezierPath在drawRect中使用。

UIBezierPath的屬性介紹:

1.CGPath:將UIBezierPath類(lèi)轉(zhuǎn)換成CGPath,類(lèi)似于UIColor的CGColor

2.empty:只讀類(lèi)型,路徑上是否有有效的元素

3.bounds:和view的bounds是不一樣的,它獲取path的X坐標(biāo)、Y坐標(biāo)、寬度,但是高度為0

4.currentPoint:當(dāng)前path的位置,可以理解為path的終點(diǎn)

5.lineWidth:path寬度

6.lineCapStyle:path端點(diǎn)樣式,有3種樣式

kCGLineCapButt:無(wú)端點(diǎn)

kCGLineCapRound:圓形端點(diǎn)

kCGLineCapSquare:方形端點(diǎn)(樣式上和kCGLineCapButt是一樣的,但是比kCGLineCapButt長(zhǎng)一點(diǎn))

效果圖:

7.lineJoinStyle:拐角樣式

kCGLineJoinMiter:尖角

kCGLineJoinRound:圓角

kCGLineJoinBevel:缺角

效果圖:

8.miterLimit:最大斜接長(zhǎng)度(只有在使用kCGLineJoinMiter是才有效), 邊角的角度越小,斜接長(zhǎng)度就會(huì)越大

為了避免斜接長(zhǎng)度過(guò)長(zhǎng),使用lineLimit屬性限制,如果斜接長(zhǎng)度超過(guò)miterLimit,邊角就會(huì)以KCALineJoinBevel類(lèi)型來(lái)顯示

9.flatness:彎曲路徑的渲染精度,默認(rèn)為0.6,越小精度越高,相應(yīng)的更加消耗性能。

10.usesEvenOddFillRule:?jiǎn)坞p數(shù)圈規(guī)則是否用于繪制路徑,默認(rèn)是NO。

11. UIRectCorner:角

UIRectCornerTopLeft:左上角

UIRectCornerTopRight:右上角

UIRectCornerBottomLeft:左下角

UIRectCornerBottomRight:右下角

UIRectCornerAllCorners:所有四個(gè)角

UIBezierPath的方法介紹:

1.創(chuàng)建UIBezierPath對(duì)象:

+ (instancetype)bezierPath:

2.創(chuàng)建在rect內(nèi)的矩形:

+ (instancetype)bezierPathWithRect:(CGRect)rect:

參數(shù):rect->矩形的Frame

3.創(chuàng)建在rect里的內(nèi)切曲線(xiàn):

+ (instancetype)bezierPathWithOvalInRect:(CGRect)rect:

參數(shù):rect->矩形的Frame

4.創(chuàng)建帶有圓角的矩形,當(dāng)矩形變成正圓的時(shí)候,Radius就不再起作用:

+ (instancetype)bezierPathWithRoundedRect:(CGRect)rect cornerRadius:(CGFloat)cornerRadius

參數(shù):rect->矩形的Frame

cornerRadius->圓角大小

5.設(shè)定特定的角為圓角的矩形:

+ (instancetype)bezierPathWithRoundedRect:(CGRect)rect byRoundingCorners:(UIRectCorner)corners cornerRadii:(CGSize)cornerRadii

參數(shù):rect->矩形的Frame

corners->指定的圓角

cornerRadii->圓角的大小

6.創(chuàng)建圓弧+ (instancetype)bezierPathWithArcCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise

參數(shù):center->圓點(diǎn)

radius->半徑

startAngle->起始位置

endAngle->結(jié)束為止

clockwise->是否順時(shí)針?lè)较?/p>

起始位置參考圖:

7.通過(guò)已有路徑創(chuàng)建路徑:

B+ (instancetype)bezierPathWithCGPath:(CGPathRef)CGPath

參數(shù):CGPath->已有路徑

8.init方法:

- (instancetype)init

9.initWiteCoder方法:

- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder

10.轉(zhuǎn)換成CGPath:

- (CGPathRef)CGPath

11.移動(dòng)到某一點(diǎn):

- (void)moveToPoint:(CGPoint)point

參數(shù):point->目標(biāo)位置

12.繪制一條線(xiàn):

- (void)addLineToPoint:(CGPoint)point

參數(shù):point->目標(biāo)位置

13.創(chuàng)建三次貝塞爾曲線(xiàn):

- (void)addCurveToPoint:(CGPoint)endPoint controlPoint1:(CGPoint)controlPoint1 controlPoint2:(CGPoint)controlPoint2

參數(shù):endPoint->終點(diǎn)

controlPoint1->控制點(diǎn)1

controlPoint2->控制點(diǎn)2

參照?qǐng)D:

14.創(chuàng)建二次貝塞爾曲線(xiàn):

- (void)addQuadCurveToPoint:(CGPoint)endPoint controlPoint:(CGPoint)controlPoint

參數(shù):endPoint->終點(diǎn)

controlPoint->控制點(diǎn)

參照?qǐng)D:

15.添加圓?。?/p>

- (void)addArcWithCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise

參數(shù):參看創(chuàng)建圓弧

16.閉合路徑,即在終點(diǎn)和起點(diǎn)連一根線(xiàn):

- (void)closePath;

17.清空路徑:

- (void)removeAllPoints;

18.追加路徑:

- (void)appendPath:(UIBezierPath *)bezierPath

參數(shù):bezierPath->追加的路徑

19.扭轉(zhuǎn)路徑,即起點(diǎn)變成終點(diǎn),終點(diǎn)變成起點(diǎn):

- (UIBezierPath *)bezierPathByReversingPath

20.路徑進(jìn)行仿射變換:

- (void)applyTransform:(CGAffineTransform)transform;

參數(shù):transform->仿射變換

21.繪制虛線(xiàn):

- (void)setLineDash:(nullable const CGFloat *)pattern count:(NSInteger)count phase:(CGFloat)phase

參數(shù):pattern->C類(lèi)型線(xiàn)性數(shù)據(jù)

count->pattern中數(shù)據(jù)個(gè)數(shù)

phase-> 起始位置

22.填充:

- (void)fill

23.描邊,路徑創(chuàng)建需要描邊才能顯示出來(lái):

- (void)stroke;

24.設(shè)置描邊顏色,需要在設(shè)置后調(diào)用描邊方法:

[[UIColor blackColor] setStroke];

25.設(shè)置填充顏色,需要在設(shè)置后調(diào)用填充方法

[[UIColor redColor] setFill];

26.設(shè)置描邊的混合模式:

- (void)fillWithBlendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha

參數(shù):blendMode->混合模式

alpha->透明度

27.設(shè)置填充的混合模式:

- (void)strokeWithBlendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha;

參數(shù):blendMode->混合模式

alpha->透明度

28.修改當(dāng)前圖形上下文的繪圖區(qū)域可見(jiàn),隨后的繪圖操作導(dǎo)致呈現(xiàn)內(nèi)容只有發(fā)生在指定路徑的填充區(qū)域

- (void)addClip;

GitHub地址:https://github.com/Locking-Xu/UIBezierPath

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • UIBezierPath Class Reference 譯:UIBezierPath類(lèi)封裝了Core Graph...
    鋼鉄俠閱讀 1,943評(píng)論 0 3
  • 使用UIBezierPath類(lèi)可以創(chuàng)建基于矢量的路徑,這個(gè)類(lèi)在UIKit中。 此類(lèi)是Core Graphics框架...
    XLsn0w閱讀 1,079評(píng)論 0 2
  • UIBezierPath介紹 基本介紹: UIBezierPath可以用來(lái)創(chuàng)建矢量的路徑和圖形,使用此類(lèi)可以定義各...
    BigDaddy_閱讀 2,712評(píng)論 0 7
  • UIBezierPath詳解 我在寫(xiě)本篇文章之前,也沒(méi)有系統(tǒng)學(xué)習(xí)過(guò)貝塞爾曲線(xiàn),只是曾經(jīng)某一次的需求需要使用到,才臨...
    白水灬煮一切閱讀 1,281評(píng)論 0 4
  • 基礎(chǔ)知識(shí) 使用UIBezierPath可以創(chuàng)建基于矢量的路徑,此類(lèi)是Core Graphics框架關(guān)于路徑的封裝。...
    十里桃花不及你閱讀 955評(píng)論 0 5

友情鏈接更多精彩內(nèi)容