Re: Sizing NSScrollView width to exactly fit NSTableView
Re: Sizing NSScrollView width to exactly fit NSTableView
- Subject: Re: Sizing NSScrollView width to exactly fit NSTableView
- From: Jonathan Mitchell <email@hidden>
- Date: Wed, 08 Jul 2015 13:02:48 +0100
Hi
Try constraining the document view (your table view in this case), to the width of the scroll content view (the NSClipView instance).
You will also need to ensure that the columns are sized in such a way as to fit the prevailing table view frame width.
NSDictionary *viewsDict = @{@"documentView" : self.view, @"contentView" : scrollView.contentView};
NSString *vfl = nil;
vfl = @“H:|-0-[documentView]-0-|";
NSArray *vConstraints = [NSLayoutConstraint constraintsWithVisualFormat:vfl options:0 metrics:nil views:viewsDict];
[scrollView.contentView addConstraints:vConstraints];
HTH
Jonathan
> On 7 Jul 2015, at 16:07, Matthew LeRoy <email@hidden> wrote:
>
> Hi,
>
> I’m trying to figure out how to correctly calculate the required width of an NSScrollView such that it will exactly fit the NSTableView inside, with no horizontal scroller and no “filler column” to the right of the last column in the table.
>
> The number of columns in the table changes based on the selection in an NSPopUpButton elsewhere on the screen. The columns are all the same width and are not resizable. When a new selection is made in the popup button, I want to reset the table with however many columns correspond to that selection, and then resize the scroll view’s width to exactly fit those columns. Both the height of the scroll view and the number of rows in the table are fixed, and there are more rows than will fit in the scroll view’s height so there will always be vertical scrolling — either legacy or overlay style depending on the user’s preference — so I need to account for the width of the vertical scroller when calculating the required width of the scroll view, if using a legacy scroller.
>
> From reading the docs, I gather that [NSScrollView frameSizeForContentSize:horizontalScrollerClass:verticalScrollerClass:borderType:controlSize:scrollerStyle] can be used to calculate the required frame size for the scroll view — but I don’t know how to calculate the required size of the table view to pass as the first argument (contentSize). I tried simply summing the column widths and using a dummy value for the height (since the height of the scroll view is fixed anyway), but that didn’t quite work (as I expected it wouldn’t) — the returned size wasn’t wide enough.
>
> Any pointers?
>
> Thanks!
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
Regards
Jonathan Mitchell
Mugginsoft LLP
email@hidden
-----------------------------------------------------------------------------
KosmicTask - the Integrated Scripting Environment for OS X.
http://www.mugginsoft.com/KosmicTask
-----------------------------------------------------------------------------
Follow on Twitter @KosmicTask
-----------------------------------------------------------------------------
Github http://github.com/mugginsoft
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden