NSSplitView autoresize only 1 of the 2 custom views

  • Is there a way to get NSSplitView to only resize 1 of the views when
    expanding a window?

    This would work similarly to Finder or iTunes where the left view
    would stay fixed in width but the right view would expand when
    resizing a window.  I've played around with the autoresizes subviews
    checkbox, but haven't been able to work it successfully.

    Thanks,
    Steven
  • On 9 jan 2008, at 19.13, Steven Crosley wrote:

    > Is there a way to get NSSplitView to only resize 1 of the views when
    > expanding a window?
    >
    > This would work similarly to Finder or iTunes where the left view
    > would stay fixed in width but the right view would expand when
    > resizing a window.  I've played around with the autoresizes subviews
    > checkbox, but haven't been able to work it successfully.
    >

    Hi!

    I think you have to do this with code. Put something like this in your
    NSSplitView delegate:

    - (void)splitView:(NSSplitView *)sender resizeSubviewsWithOldSize:
    (NSSize)oldSize
    {
        CGFloat dividerThickness = [sender dividerThickness];
        NSRect leftRect  = [[[sender subviews] objectAtIndex:0] frame];
        NSRect rightRect = [[[sender subviews] objectAtIndex:1] frame];
        NSRect newFrame  = [sender frame];

        leftRect.size.height = newFrame.size.height;
        leftRect.origin = NSMakePoint(0, 0);
        rightRect.size.width = newFrame.size.width - leftRect.size.width
    - dividerThickness;
        rightRect.size.height = newFrame.size.height;
        rightRect.origin.x = leftRect.size.width + dividerThickness;

        [[[sender subviews] objectAtIndex:0] setFrame:leftRect];
        [[[sender subviews] objectAtIndex:1] setFrame:rightRect];
    }

    Cheers,

    Peter
previous month january 2008 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