9

いくつかの点の間に点線を引く必要があるアプリケーションを開発しています。私は試した

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

しかし、点線ではなく破線が表示されます。代わりに点線を取得するにはどうすればよいですか?

4

2 に答える 2

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

このコードは正しく機能するはずです。

于 2012-08-09T08:10:11.113 に答える
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);
于 2016-09-01T02:55:03.510 に答える