• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Stack?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Stack?


  • Subject: Stack?
  • From: Charles Jenkins <email@hidden>
  • Date: Fri, 03 Oct 2014 21:06:52 -0400

Okay, here’s a dumb question… How do you make a stack view actually stack
things? When I add subviews into a stack view, instead of appearing one after
another as I expect, they’re all laid on top of one another.

I created a sample program with one window filled with a scroll view, and
inside that a stack view. My Document class just throws in a bunch of subviews
(quickies made with NSBox), and no matter what layout alignment I choose, they
appear overlaid on one another. Here’s the bit of code that matters:

@interface Document ()

@property (weak) IBOutlet NSStackView* theStack;
@property NSArray* heightArray;

@end

@implementation Document

- (instancetype)init {
    self = [super init];
    if (self) {
      self.heightArray = @[ @50, @70, @25, @90, @25, @150, @50, @200, @30, @75, @25, @90, @150, @300, @80, @50 ];
    }
    return self;
}

- (void)windowControllerDidLoadNib:(NSWindowController *)aController {
  [super windowControllerDidLoadNib:aController];
  // Add any code here that needs to be executed once the windowController has loaded the document's window.

  self.theStack.alignment = NSLayoutAttributeBottom;

  unsigned long count = [self.heightArray count];
  for ( unsigned long ix = 0; ix < count; ++ix ) {
    NSRect rect = CGRectMake(0, 0, 75, [[self.heightArray objectAtIndex: ix] doubleValue] );
    NSBox* box = [[NSBox alloc] initWithFrame: rect];
    box.fillColor = [NSColor blueColor];
    box.borderType = NSLineBorder;
    box.borderWidth = 20;
    box.borderColor = [NSColor magentaColor];
    box.titlePosition = NSNoTitle;
    [self.theStack insertView:box atIndex:ix inGravity:NSStackViewGravityCenter];
  }
}




—

Charles Jenkins

_______________________________________________

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


  • Follow-Ups:
    • Re: Stack?
      • From: Jonathan Mitchell <email@hidden>
  • Prev by Date: Re: NSTableView with reversed rows?
  • Next by Date: A Stack of Editors
  • Previous by thread: Re: NSTableView with reversed rows?
  • Next by thread: Re: Stack?
  • Index(es):
    • Date
    • Thread