开发者

Code equivalent for size property in Interface Builder

开发者 https://www.devze.com 2023-04-11 07:29 出处:网络
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, re开发者_如何学Gogular)

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, re开发者_如何学Gogular). 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];
0

精彩评论

暂无评论...
验证码 换一张
取 消