开发者

Simple square that can change color in Interface Builder/Cocoa

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.


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)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜