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:
- Create an
NSView
subclass for the whole grid - Create an
NSView
subclass for each grid square - Create an
NSCell
subclass and use it withNSMatrix
- Use an
NSBox
for each grid square (like Ahruman suggests) - Use an
NSImageView
for each grid square and and pass them anNSImage
I'd use option 1 or 3.
I don't think Core Animation can provide any simpler solutions.
精彩评论