Small NSTableView

  • I played a bit with Interface Builder last night. I wanted to create a smaller size (i.e. like small and mini in some controls) for the NSTableView.

    I found that I could adjust the row height in pixels but of course when I do that the font no longer fits. What is the right way to have a small NSTableView?

    I am using the term "small" because in Interface Builder there are a number of controls that have attributes that allow you to adjust the size of say a button to be "regular", "small" or "mini".

    Thanks for your help as always!

    -mark=
  • On Oct 27, 2006, at 6:16 PM, Mark Manes wrote:

    > I played a bit with Interface Builder last night. I wanted to
    > create a smaller size (i.e. like small and mini in some controls)
    > for the NSTableView.
    >
    > I found that I could adjust the row height in pixels but of course
    > when I do that the font no longer fits. What is the right way to
    > have a small NSTableView?

    There are a couple of ways to do this. One is to implement the -
    willDisplayCell:forTableColumn:row: method in the table's data-source/
    delegate and set the font explicitly like this:

    - (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell
    forTableColumn:(NSTableColumn *)aTableColumn                                 row:(int)rowIndex
    {
    [aCell setFont:[NSFont systemFontOfSize:11.0]];  // or pick your own
    font
    }

    Another way to do it is to have your -objectValueForTableColumn:row:
    method return an attributed string, like this:

    - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:
    (NSTableColumn *)aTableColumn row:(int)rowIndex
    {
    return [[NSAttributedString alloc] initWithString:myString
    attributes:myAttributes];
    }

    (usual caveats about autoreleasing omitted for brevity)

    HTH,

    Glenn Zelniker
  • On Oct 27, 2006, at 6:32 PM, Glenn Zelniker wrote:
    > [aCell setFont:[NSFont systemFontOfSize:11.0]];  // or pick your
    > own font

      Or you could use:

    [aCell setFont:[NSFont controlContentFontOfSize:[NSFont
    systemFontSizeForControlSize:NSSmallControlSize]]];

      ... to get the actual system font and size for a small control. :-)

    --
    I.S.
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today