Question

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.

Was it helpful?

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];

OTHER TIPS

Apple is now providing an official guide for this.

Here's copied code snippet.

float fontSize = [NSFont systemFontSizeForControlSize:NSMiniControlSize];
NSCell *theCell = [theControl cell];
NSFont *theFont = [NSFont fontWithName:[[theCell font] fontName] size:fontSize];
[theCell setFont:theFont];

[theCell setControlSize:NSMiniControlSize];

[theControl sizeToFit];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top