Using the NSBezierPath Class

To draw something more than just colored rectangles, a bitmapped image must be rendered, or a Quartz path must be defined and subsequently stroked or filled. Because the sample application started in the previous section is supposed to draw random line segments, the latter option makes the most sense. Cocoa uses the NSBezierPath class to define and manipulate Quartz paths.

There are two ways to create an NSBezierPath instance. If an object is just temporary, using the +bezierPath method returns an autoreleased object with an empty path. Alternatively, for an object that will be kept around, use the standard Objective-C +alloc/-init pair to create a brand new, empty object.

After a path object is created, a path must ...

Get Cocoa® Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.