what?
在iOS中繪制矢量圖或者路徑的時(shí)候通常會用到 UIBezierPath ,它在 UIKit 中描馅,是CoreGraphics對path的封裝蜓耻。使用 UIBezierPath 母蛛,可以繪制直線因宇、橢圓、多邊形和貝塞爾曲線……祟偷。
why?
能夠基本上實(shí)現(xiàn)CGPathRef的功能察滑,它是OC語言的,相對于c語言的Core Graphics來說更為平易近人修肠。它能夠使用ARC贺辰,如果我們直接使用CGPathRef的話,還要自己負(fù)責(zé)在合適的時(shí)候釋放氛赐。
how?
//創(chuàng)建一個(gè)
UIBezierPath *bePath = [UIBezierPath bezierPath];
//開始位置
[bePath moveToPoint:CGPointMake(100, 100)];
//結(jié)束位置
[bePath addLineToPoint:CGPointMake(200, 200)];
[bePath addLineToPoint:CGPointMake(250, 150)];
//設(shè)置線段端顯示的樣式
bePath.lineCapStyle = kCGLineCapRound;
//設(shè)置拐角的樣式
bePath.lineJoinStyle = kCGLineJoinRound;
//設(shè)置邊的顏色
[[UIColor redColor] setStroke];
//設(shè)置邊的寬度
bePath.lineWidth = 5.0;
//繪畫
[bePath stroke];
更多復(fù)雜的繪制請參考Demo.
way
請猛烈點(diǎn)擊: Demo地址