【问题标题】:Draw dotted lines using Quartz on iPhone在 iPhone 上使用 Quartz 绘制虚线
【发布时间】:2010-06-28 13:42:07
【问题描述】:

我正在开发一个应用程序,我需要在几个点之间绘制虚线。我试过了

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

但我看到的是虚线而不是虚线。我怎样才能得到虚线?

【问题讨论】:

标签: iphone drawing quartz-graphics dotted-line


【解决方案1】:
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);

这段代码应该可以正常工作。

【讨论】:

    【解决方案2】:

    请参阅以下关于线属性角色的精彩页面! 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-08
      • 1970-01-01
      • 2010-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多