NSSize buttonSize; buttonSize = [myButton frame].size;frame is a method inherited by NSView which returns the rectangle enclosing the button (or, more generally, the rectangle enclosing/represented by an NSView). The origin of this rectangle is meaningless at this point; it is the size (which was set by sizeToFit) what we want.
Then, we choose for the window a content rect with the size of the button, and with an origin of our choice; (100, 100) in this example:
NSRect rect; rect = NSMakeRect (100, 100, buttonSize.width, buttonSize.height);At this point, we just create the window as before, but using this rectangle (full code below). The last thing to do is then replacing the default window content view with our button:
[myWindow setContentView: myButton];