Re: Making NSBox programmatically
Re: Making NSBox programmatically
- Subject: Re: Making NSBox programmatically
- From: "John C. Randolph" <email@hidden>
- Date: Mon, 13 Feb 2006 18:58:03 -0800
On Feb 13, 2006, at 6:30 PM, Alan Smith wrote:
I need to make a box through code and not through IB. The idea's to
add a
NSBox to place an icon in when the user presses a button, like the
dock when
you drag an app/folder on to it; it expands. I can expand the
window with
setContentSize, and that works fine. But I can't figure out how to
create
the box and place it.
Okay, here is the window, ignore the " ' ", they're just to make it
look
good.
Window:
---------------------
| |----------------| |
| | | |
| | The' | |
| | Box' | |
| |----------------| |
---------------------
Nice, no? Okay, there's the window and a NSBox inside it. Now I
want to
create another box when the user press's a button.
----------------------------------------
| |----------------| |----------------| |
| | | | | |
| | The' | | The' | |
| | Box' | | Box'' | |
| |----------------| |----------------| |
----------------------------------------
Now I can, like I said, expand the window easily, but the creation
of the
box is the difficult part. Once created how do I get it to line up
with the
other box?
In whatever object that's getting the message from the button, do
something like this:
id firstBox;
id newBox;
...
NSRect newBoxFrame = [firstBox frame];
newBoxFrame.origin.x += NSWidth(newBoxFrame); // Shift it along the
X axis.
newBox = [[NSBox alloc] initWithFrame:newBoxFrame]; // create the
new NSBox instance
[[firstBox superview] addSubview:newBox]; // Insert it into the view
hierarchy
-jcr
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden