Domanda

Sto sviluppando un'applicazione in cui ho bisogno di disegnare linee tratteggiate tra un paio di punti. Ho cercato

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

Ma vedere linee tratteggiate anziché linee tratteggiate. Come posso ottenere linee tratteggiate, invece?

È stato utile?

Soluzione

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

Questo codice dovrebbe funzionare correttamente.

Altri suggerimenti

, vedere il seguente grande pagina circa i ruoli di proprietà della linea! https://horseshoe7.wordpress.com/2014/ 07/16 / core-grafici-line-drawing-spiegato /

Secondo la pagina di cui sopra, ecco il codice per la linea 'punto' come (...).

// 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);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top