2010-06-28 9 views
9

पर क्वार्ट्ज का उपयोग करके बिंदीदार रेखाएं ड्रा करें मैं एक ऐसा एप्लीकेशन विकसित कर रहा हूं जिसमें मुझे दो बिंदुओं के बीच बिंदीदार रेखाएं खींचना पड़े। मैंने कोशिश कीआईफोन

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

लेकिन मुझे बिंदीदार रेखाओं के बजाय धराशायी रेखाएं दिखाई देती हैं। मैं इसके बजाय बिंदीदार रेखा कैसे प्राप्त कर सकता हूं?

+0

https://developer.apple.com/library/ios/# प्रलेखन/ग्राफिक्स इमेजिंग/संकल्पनात्मक/drawingwithquartz2d/dq_paths/dq_paths.html – Jay

+0

यह एक पुरानी पोस्ट है, लेकिन उपर्युक्त टिप्पणी वास्तव में मदद नहीं करती है। उस लिंक में ड्राइंग डॉट्स शामिल नहीं हैं। –

+1

यकीन है कि यह करता है। "चित्रकारी पथ" पर एक पूरा अनुभाग है जहां यह वर्णन करता है कि CGContextSetLineDash https://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CGContext/Reference/reference का उपयोग करके "लाइन डैश पैटर्न" को कैसे आकर्षित किया जाए .html # // apple_ref/doc/c_ref/CGContextSetLineDash – pinkeerach

उत्तर

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); 

यह कोड सही ढंग से काम करना चाहिए।

0

कृपया, लाइन गुणों की भूमिकाओं के बारे में निम्नलिखित महान पृष्ठ देखें! https://horseshoe7.wordpress.com/2014/07/16/core-graphics-line-drawing-explained/

ऊपर पृष्ठ के अनुसार, यहां की तरह 'डॉट' लाइन के लिए कोड है (।।।।)

// 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);