NSStackView basics
NSStackView basics
- Subject: NSStackView basics
- From: Tom Harrington <email@hidden>
- Date: Fri, 08 Nov 2013 18:02:37 -0700
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