2013-08-30 21 views
3

參考以下圖片:繪製以筆刷形狀結尾的線條?

enter image description here

。 。 。 。注意它如何不以適當的點結束。

我用下面的繪製代碼:

CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextSetLineWidth(context, 2.0); 
CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor); 

CGContextMoveToPoint(context, self.width - 20, (self.height/2) - 5); 
CGContextAddLineToPoint(context, self.width - 12, self.height/2); 
CGContextStrokePath(context); 

CGContextMoveToPoint(context, self.width - 20, (self.height/2) + 5); 
CGContextAddLineToPoint(context, self.width - 12, self.height/2); 
CGContextStrokePath(context); 

有一種簡單的方式說,一個行應該在一個點結束?我知道我可以通過略微修改座標來解決此問題,但我很想了解更多信息。

回答

2

行未加入,所以CGLineJoin樣式不生效。以下代碼應該沒問題:

CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextSetLineWidth(context, 2.0); 
CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor); 

CGContextMoveToPoint(context, self.width - 20, (self.height/2) - 5); 
CGContextAddLineToPoint(context, self.width - 12, self.height/2); 
CGContextAddLineToPoint(context, self.width - 20, self.height/2 + 5); 
CGContextStrokePath(context);