Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

lpetrich

macrumors member
Original poster
Nov 26, 2009
39
0
For the last few hours, I have been attempting to embed a NSBox in a NSScrollView, so that the box will be partially displayed with scrollbars for scrolling through it if it is too large for the window.

I do the recommended procedure of creating a box, selecting it, then doing Editor > Embed In > Scroll View.

I then constrain the scroll view to be the same size as the window, so that when the window is resized, the scroll view is also. That works, but the problem is with the box.

I've been unable to pin the box's upper left corner to the view's upper left corner, while keeping the box's size fixed. In fact, I want to change the box's size programmatically for the content that I want for it -- content that I intend to place programmatically.

Is there any way to get my desired behavior by using some suitable combination of constraints created in Xcode's nib/xib editor? Or will I have to do it programmatically?
 
After some hours of trying to do it with Xcode's GUI-layout editor (formerly the Interface Builder), I decided to do it programmatically and use some of Apple's sample code as a guide.

This code resides in a NSWindowController subclass and the content is Bkgd.
NSWindow *SelfWindow = [self window];
NSScrollView *Scroller = [[NSScrollView alloc] initWithFrame:[[SelfWindow contentView] frame]];
[Scroller setHasVerticalScroller:YES];
[Scroller setHasHorizontalScroller:YES];
[Scroller setBorderType:NSNoBorder];
[Scroller setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
[Scroller setDocumentView:Bkgd];
[SelfWindow setContentView:Scroller];
[SelfWindow makeKeyAndOrderFront:nil];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.