2010-06-28 8 views
9

Estoy desarrollando una aplicación en la que necesito dibujar líneas punteadas entre un par de puntos. IntentéDibuja líneas de puntos usando Quartz en iPhone

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

Pero veo líneas punteadas en lugar de líneas punteadas. ¿Cómo puedo obtener líneas punteadas?

+0

https://developer.apple.com/library/ios/# documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_paths/dq_paths.html – Jay

+0

Esta es una publicación anterior, pero el comentario anterior en realidad no ayuda. Ese enlace no cubre los puntos de dibujo. –

+1

Claro que sí. Hay una sección completa sobre "Pintar un camino" en la que se describe cómo dibujar un "patrón de línea de guiones" utilizando CGContextSetLineDash https://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CGContext/Reference/reference .html # // apple_ref/doc/c_ref/CGContextSetLineDash – pinkeerach

Respuesta

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

Este código debería funcionar correctamente.

0

Por favor, consulte la siguiente gran página sobre los roles de las propiedades de línea. https://horseshoe7.wordpress.com/2014/07/16/core-graphics-line-drawing-explained/

De acuerdo a la página anterior, aquí es el código de la línea 'punto' como (....)

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