What's the preferred/recommended way to draw a line in NSView-drawRect: method?

eonil picture eonil · May 7, 2011 · Viewed 12.2k times · Source

I couldn't found any line drawing primitive in Cocoa at NSView level. The only thing I've been found is NSBezierPath. Is this a preferred way? Or is there another way which I couldn't discovered?

Answer

Rob Keniger picture Rob Keniger · May 8, 2011

NSBezierPath is exactly what you should be using. If you just want to draw a straight line from one point to another, use the class method:

+strokeLineFromPoint:(NSPoint)point1 toPoint:(NSPoint)point2