Color Well Cell

What is it?

LVColorWellCell is a Cocoa NSActionCell derived class to allow displaying and picking colors from a Table View.

Usage without a Delegate

  1. Connect the table view to your Array Controller and bind the columns like you always do.
  2. Make sure that the identifier property is populated for the color column. Interface Builder Identifier Property
  3. Add the following code to the awakeFromNib of your controller.
    // Replace @"color" with the identifier you provided in step 2.
    NSUInteger index = [colorTable columnWithIdentifier:@"color"];
    NSTableColumn * colorColumn = [[colorTable tableColumns] objectAtIndex:index];
    LVColorWellCell * colorCell = [[LVColorWellCell alloc] init];
    // This is the property name of the color value in the object/dictionary bound to the table view.
    [colorCell setColorKey:@"color"];
    [colorColumn setDataCell:colorCell];
  4. All Done. Your color wells should show and work nicely.

Usage with a Delegate

Delegate support right now fairly basic. The delegate can choose to return the color and replace the color when the user interacts with the color picker after clicking on the cell. The following protocol(not enforced) should spell out the expected behavior.

@protocol LVColorWellCellDelegate

-(void)colorCell:(LVColorWellCell *)colorCell
            setColor:(NSColor *)color

-(NSColor *)colorCell:(LVColorWellCell *)colorCell


Take a look at the demo project for a complete and working example for using delegates.

Features in the back-burner

  • Interface Builder Palette
  • Enhanced delegation
  • More drawing styles(Border styles etc)

Copyright © Ringce 2008-2009. Powered by hyde.