2013-06-03 51 views
0

我已經知道如何在2點之間劃一條線,但是線看起來並不那麼光滑。我能做些什麼來使它更平滑?謝謝。如何平滑iOS中2點之間的界限?

- (void)drawLineFrom:(CGPoint)start To:(CGPoint)end { 
// begin image context 
UIGraphicsBeginImageContext(self.imageLineView.frame.size); 

// define image rect for drawing 
[self.imageLineView.image drawInRect:CGRectMake(0, 0, imageLineView.frame.size.width, imageLineView.frame.size.height)]; 

// set line properties 
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); 
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 2.0f); 
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0f, .0f, .0f, 1.0); 

// move context to start point 
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), start.x, start.y); 

// define path to end point 
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), end.x, end.y); 

// stroke path 
CGContextStrokePath(UIGraphicsGetCurrentContext()); 

// flush context to be sure all drawing operations were processed 
CGContextFlush(UIGraphicsGetCurrentContext()); 

// get UIImage from context and pass it to our image view 
imageLineView.image = UIGraphicsGetImageFromCurrentImageContext(); 

// end image context 
UIGraphicsEndImageContext(); 
} 

enter image description here

+0

你是什麼意思「不光滑」?你有兩點,你會得到他們之間的一條直線。什麼順利呢? – Abizern

+1

試試這個http://tonyngo.net/2011/09/smooth-line-drawing-in-ios/ – Liolik

+0

@Abizern:這條線有點鋸齒。 –

回答

3

可以使用貝塞爾路徑畫出流暢的線條。

您可以在這裏獲得更多信息。 Bézier Paths

0

嘗試啓用反鋸齒。您需要在Info.plist中將UIViewEdgeAntialiasing項設置爲YES。