Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Basic Drawing

There are two absolute essentials if you want to do any drawing: a color and something to draw. You use the NSColor class to create colors, and the “something” can be a simple rectangle to start. Well, actually, there’s a third thing: you need somewhere to draw. In this case, the “somewhere” will be a view.

NSColor

The NSColor class can do some fairly impressive tricks, but I just want to introduce you to the basics. Here’s a simple set of examples that demonstrates almost everything you’ll need on a day-to-day basis:

// basic color constants.
NSColor* color1 = [NSColor redColor];
NSColor* color2 = [NSColor greenColor];
NSColor* color3 = [NSColor blueColor];
NSColor* color4 = [NSColor purpleColor];
NSColor* color5 = [NSColor yellowColor];
NSColor* color6 = [NSColor orangeColor];

// completely transparent.
NSColor* color7 = [NSColor clearColor];

// color by channel, including alpha.
NSColor* color8 = [NSColor colorWithCalibratedRed: 0.25
                                            green: 0.30
                                             blue: 0.45
                                            alpha: 1.0];

// white value with alpha.
NSColor* color9 = [NSColor colorWithCalibratedWhite: 0.45
                                              alpha: 0.8];

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint