在iPhone上使用石英绘制虚线
-
01-10-2019 - |
题
我正在开发一个应用程序,其中我需要在几个点之间绘制虚线。我试过
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-explain//
根据上一页,这是“点”行的代码,例如(……)
// 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);
不隶属于 StackOverflow