views:

100

answers:

2

Hi there, For an application that I am developing I need to create a grid of squares. The only relevant property they should have is the ability to change to any color (RGB).

1) What kind of object should I use? Custom? 2) Am I overlooking something? Should I, for instance, be using Core Animation?

Thanks in advance.

+1  A: 

It really depends on the size of your grid, but for something small (up to a few dozen squares not changing more than a few times a second, say) or prototyping, you can use NSBox. In IB, set Box Type to Custom and Border Type to None. You can then set the fillColor attribute as desired. (Mac OS X 10.5 or later)

Ahruman
Cool, thanks. Ill try it right away.
Job
A: 

Off the top of my head, you could:

  1. Create an NSView subclass for the whole grid
  2. Create an NSView subclass for each grid square
  3. Create an NSCell subclass and use it with NSMatrix
  4. Use an NSBox for each grid square (like Ahruman suggests)
  5. Use an NSImageView for each grid square and and pass them an NSImage

I'd use option 1 or 3.

I don't think Core Animation can provide any simpler solutions.

Benedict Cohen
Thanks, I think I'm going for option 3. I'm also trying Ahruman's anwser, maybe even compare them for fun's sake.
Job