Re: NSStackView basics
Re: NSStackView basics
- Subject: Re: NSStackView basics
- From: Ken Ferry <email@hidden>
- Date: Mon, 11 Nov 2013 17:29:37 -0800
Hi Tom,
I think the problem here is that if you have view A containing textField,
and textField is centered in A, there's no constraint expressing anything
about A's height. A can go to zero height and still have the textField
centered within it.
If you added something giving a height (or fastened the edges of A to the
textField), that'd probably do it.
-ken
On Fri, Nov 8, 2013 at 5:02 PM, Tom Harrington <email@hidden> wrote:
> I'm trying to use NSStackView in what should be the most basic way
> possible. I create the stack view and add two subviews. But only one of
> them is ever visible.
>
> I'm creating the stack view in code (in my app delegate, for purposes of a
> test project):
>
> NSStackView *stackView = [NSStackView stackViewWithViews:@
> [self.subview1,
> self.subview2]];
>
> stackView.orientation = NSUserInterfaceLayoutOrientationVertical;
>
> stackView.alignment = NSLayoutAttributeCenterX;
>
> stackView.spacing = 0;
>
> [self.window.contentView addSubview:stackView];
>
> [self.window.contentView addConstraints:[NSLayoutConstraint
> constraintsWithVisualFormat:@"H:|-(50)-[stackView]-(50)-|"
>
>
> options:0
>
>
> metrics:nil
>
>
> views:NSDictionaryOfVariableBindings(stackView)]];
>
> [self.window.contentView addConstraints:[NSLayoutConstraint
> constraintsWithVisualFormat:@"V:|-(50)-[stackView]-(50)-|"
>
>
> options:0
>
>
> metrics:nil
>
>
> views:NSDictionaryOfVariableBindings(stackView)]];
>
> The two subviews subview1 and subview2 are just plain NSViews, each with an
> NSTextField label subview constrained to be in the center.
>
> At run time, only one subview is visible-- the last one in the array. It's
> resized to fill the entire stack view. If I resize the window, the stack
> view and the one visible subview also resize, but no window size ever gets
> both subviews showing.
>
> Obviously I'm missing something basic about stack views, but I don't know
> what. I've been looking at Apple's InfoBarStackView demo app but haven't
> worked out which detail it has that I don't (Apple's demo:
>
> https://developer.apple.com/library/mac/samplecode/InfoBarStackView/Introduction/Intro.html
> )
>
> --
> Tom Harrington
> email@hidden
> AIM: atomicbird1
> _______________________________________________
>
> 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
_______________________________________________
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