An implementation of the colour well seen in Pages 5, Numbers 3 and Keynote 6.
All custom drawing is done with NSBezierPath (cached where possible), the usual NSEvent methods (-mouseDown:, -mouseUp:, -mouseDrag) are implemented to keep track of the control's state and turn on or off different drawing options. Colours can be dragged and dropped into or out of the colour well using the systems NSColorPanel. Delegate methods should be implemented to fill the popover grid with colour cells.
Any improvements welcomed.
- Want to add the ability to display custom views in the popover (from a user specified content view controller), this will enable users to design their own layout of colour cells etc.
-
Drag out an NSView into a XIB
-
Change the class to
DFColorWell
-
Add placeholder intrinsic size to 67 by 23.
NB DFColorWell sets the
intrinsicContentSize
because the control will always have a fixed size, so size constraints should not be used. -
Optionally Implement the delegate methods which fills the pop over with different colours. If you do not implement these delegate methods an internal delegate object will be created which provide the default colours shown above in the main screenshot.
- (NSUInteger) numberOfRowsInColorWell:(DFColorWell*)colorWell;
- (NSUInteger) numberOfColumnsInColorWell:(DFColorWell*)colorWell;
- (NSColor*) colorWell:(DFColorWell*)colorWell colorAtColumn:(NSUInteger)column row:(NSUInteger)row;
- Daniel Farrell
- @danieljfarrell
- http://daniel.farrell.name
DFColorWell is licensed under the BSD license.