0

I am using the following code to draw a line graph on a custom NSView

for var index = 0; index < (dataPointsArray.count - 1); index++ {
    NSBezierPath().lineWidth = 20.0
    NSBezierPath.strokeLineFromPoint(dataPointsArray[index], toPoint: dataPointsArray[index + 1])
}

This snippet is contained within a function that is called by drawRect() within the Custom View.

The line draws correctly within the coordinate system of the view. However, the line is drawn at the same width (one pixel width) regardless of the .lineWidth setting (e.g., 5.0, 10.0, 20.0 etc) which seems to have no impact on the line that is actually drawn).

Is anyone able to advise what might be creating this issue for me. I haven't been able to find a previous question that raises this issue.

Wolfstar
  • 111
  • 10
  • Both responses below from Zoff Dino and GeneratorOfOne work. I have elected to use initialising an instance of NZBezierPath as it creates a more readable code for me given that I am doing this in a range of difference functions. Thanks for the responses. – Wolfstar Jul 08 '15 at 14:13

1 Answers1

0
NSBezierPath().lineWidth = 20.0

The () means you are initializing a new instance of the class and set its lineWidth to 20.0. You should create a variable and use it to draw your path:

var bezierPath = NSBezierPath()

bezierPath.lineWidth = 20.0
bezierPath.moveToPoint(dataPointsArray[index])
bezierPath.lineToPoint(dataPointsArray[index + 1])
Code Different
  • 90,614
  • 16
  • 144
  • 163