Question

Je développe une application dans laquelle je dois tracer des lignes en pointillés entre deux points. J'ai essayé

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

Mais je vois des lignes en pointillés au lieu de lignes en pointillés. Comment puis-je obtenir la place des lignes en pointillés?

Était-ce utile?

La solution

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

Ce code doit fonctionner correctement.

Autres conseils

S'il vous plaît, voir la page suivante sur les grands rôles des propriétés en ligne! https://horseshoe7.wordpress.com/2014/ 07/16 / core-graphiques de ligne de dessin expliquée /

D'après la page ci-dessus, voici le code pour la ligne 'dot' comme (...).

// 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);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top