Pregunta

estoy desarrollando una aplicación en la que necesito para dibujar líneas de puntos entre un par de puntos. Probé

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

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

¿Fue útil?

Solución

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.

Otros consejos

Por favor, consulte la siguiente gran página sobre el papel de propiedades de la línea! https://horseshoe7.wordpress.com/2014/ 07/16 / de núcleo de gráficos de línea de dibujo-explicado /

De acuerdo a la página anterior, aquí está el código para la línea de '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);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top