2010-06-28 38 views
9

Tôi đang phát triển một ứng dụng mà tôi cần vẽ các đường chấm chấm giữa một vài điểm. Tôi đã thửVẽ các đường chấm chấm bằng cách sử dụng Quartz trên iPhone

CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound) 
CGContextSetLineDash(UIGraphicsGetCurrentContext(), 0, lengths, LENGTH_OF_ARRAY) 

Nhưng tôi thấy các đường đứt nét thay vì các đường chấm chấm. Làm thế nào tôi có thể nhận được các đường chấm chấm thay thế?

+0

https://developer.apple.com/library/ios/# tài liệu/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_paths/dq_paths.html – Jay

+0

Đây là một bài đăng cũ, nhưng nhận xét trên không thực sự hữu ích. Liên kết đó không bao gồm các dấu chấm vẽ. –

+1

Chắc chắn rồi. Có một phần toàn bộ về "Vẽ một con đường", nơi nó mô tả làm thế nào để vẽ một "mô hình gạch ngang dòng" bằng cách sử dụng CGContextSetLineDash https://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CGContext/Reference/reference .html # // apple_ref/doc/c_ref/CGContextSetLineDash – pinkeerach

Trả lời

11
CGContextRef context = UIGraphicsGetCurrentContext(); 
CGFloat lengths[2]; 
lengths[0] = 0; 
lengths[1] = dotRadius * 2; 
CGContextSetLineCap(context, kCGLineCapRound); 
CGContextSetLineWidth(context, dotRadius); 
CGContextSetLineDash(context, 0.0f, lengths, 2); 

// CGContextAddEllipseInRect(context, self.bounds); 

Mã này sẽ hoạt động chính xác.

0

Vui lòng xem trang tuyệt vời sau về vai trò của thuộc tính dòng! https://horseshoe7.wordpress.com/2014/07/16/core-graphics-line-drawing-explained/

Theo trang ở trên, đây là mã cho dòng 'chấm' như (....)

// should 
CGContextSetLineCap(context, kCGLineCapRound); 

// please see the role of line properties why the first should be 0 and the second should be the doulbe of the given line width 
CGFloat dash[] = {0, lineWidth*2}; 

// the second value (0) means the span between sets of dot patterns defined by dash array 
CGContextSetLineDash(context, 0, dash, 2); 
Các vấn đề liên quan