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.

有帮助吗?

解决方案

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

其他提示

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];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top