Search code examples
cocoanstablecolumn

Code equivalent for size property in Interface Builder


I'm creating some NSTableColumns dynamically and they appear too tall in the table. In the Interface Builder there is a general setting to adjust the object size (mini, small, regular). Is there any code equivalent for this or should I simply select the font manually?

Update

I found that I can get the font with:

    NSFont *font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSMiniControlSize]];

However, the row height doesn't match the items' height. Setting the font in code does nothing with the row height. I use NSTextFieldCells and NSPopUpButtonCells as data cells.

Oh, and I'm building for 10.6.


Solution

  • In addition to changing the font, you need to set the control size of the cell.

    NSCell *theCell = ...;
    [theCell setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSMiniControlSize]]];
    [theCell setControlSize:NSMiniControlSize];