Re: Creating a NSScrollView programmatically
Re: Creating a NSScrollView programmatically
- Subject: Re: Creating a NSScrollView programmatically
- From: "Alastair J.Houghton" <email@hidden>
- Date: Mon, 27 Oct 2003 18:21:09 +0000
On Monday, October 27, 2003, at 11:23 am, Arthur VIGAN wrote:
Hi,
I am trying to create an NSScrollView programmatically in the content
view of a window. I have the following code, but it doesn't work
(scrollView and mainWindow are defined in the header file):
- (IBAction)createScrollView:(id)sender
{
NSView *windowContentView = [mainWindow contentView];
NSRect windowContentBounds = [windowContentView bounds];
scrollView = [[NSScrollView alloc] init];
[scrollView setBorderType:NSNoBorder];
[scrollView setHasVerticalScroller:YES];
[scrollView setBounds: windowContentBounds];
[windowContentView addSubview:scrollView];
}
When my window appears, it is just empty. Can anybody help?
You need to set the scroll view's *frame*, not its bounds. The frame
is the size of the view... the bounds define the internal co-ordinate
system *within* a view (so you don't want to set those). Try
scrollView = [[NSScrollView alloc] initWithFrame:windowContentBounds];
[scrollView setBorderType:NSNoBorder];
[scrollView setHasVerticalScroller:YES];
[windowContentView addSubView:scrollView];
instead.
You'll also want to put something in your NSScrollView, but I imagine
you were going to do that next.
Kind regards,
Alastair.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.