質問

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

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

しかし、私は点線の線の代わりに破線の線を見ます。代わりに点線を入手するにはどうすればよいですか?

役に立ちましたか?

解決

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

このコードは正しく動作するはずです。

他のヒント

ラインプロパティの役割に関する次の素晴らしいページをご覧ください!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);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top