MainMenu.xib with dispositioned main window - cocoa

Each time I create any type of cocoa project (document-based, with core-data and/or spotlight importer) and open MainMenu.xib, I get a warning sign in bottom right object palette window corner saying that window is out of screen bounds. Why is this so? Any remedy?

I get a warning sign in bottom right object palette window corner saying that window is out of screen bounds. Why is this so?
Because the window falls at least partially outside the screen bounds.
Any remedy?
Put it completely within the screen bounds. Select the window and use the Content Size & Position section of the Size (⌘3) inspector to move it.
Simply dragging the window by its title bar will not help, since that position is only for display in IB; it doesn't affect the window that will appear in your app, which is what the warning is about. You need to use the Size inspector.

I once had a similar problem when I had a second monitor connected to my MBP.
When the second monitor was set to a low resolution (I think it was 1024x768), Interface Builder came up with that particular warning. (Although the window did fit between the main menu and the Dock).

Related

How can I make window zooming respect auto layout constraints?

To keep things simple, let's say I have a window containing a single view, which has auto layout constraints binding all 4 sides to the window container view with offset 0. And assume that this view also has a constraint setting its aspect ratio to a constant value. If I resize the window manually, then then window nicely maintains the desired aspect ratio. But if I click the little green zoom widget, then the window fills up the whole screen, regardless of the aspect ratio, with part of the view being above the top of the screen. Is there some way I can make zooming resize the window as big as it can be, without violating auto layout constraints?
I couldn't very well detect this problem in the delegate method windowWillResize:toSize:, because that doesn't tell me which screen it's thinking about putting the window on. I could try to fix the window size in the windowDidResize: delegate method, at which time I do know what screen it's on, but I'm not sure exactly how to do that without reinventing Auto Layout's wheel.
Apparently someone thinks I wasn't explicit enough, so I'll try again. Steps to reproduce:
In Xcode, create a new macOS App project using XIB interface.
Open MainMenu.xib and select the window.
Reshape the window to be approximately square.
Using the Attribute Inspector, set the Full Screen behavior for the window to Auxiliary Window.
Drag an Image View from the library and drop it in the window.
In the Attributes Inspector, set the image view to show the NSComputer image and scale axes independently.
Expand the image view to fill up the window content area.
With the image view selected, click the button to add new layout constraints.
Add 5 constraints, binding the 4 sides to the container, and setting the aspect ratio. (see screen shot)
Build and Run.
Observe that if you resize the window by dragging an edge or corner, the aspect ratio remains fixed.
Click the green zoom widget in the title bar of the window, and observe that the window expands without regard for the aspect ratio constraint, cutting off part of the image.
I just set up a test project exactly as you specified, and when I invoke the window zoom widget, the window expands and retains its aspect ratio i.e. it works as expected. The only thing I can think of that might be causing your issue: maybe your content hugging and content compression resistance priorities are at odds with your constraints? Mind you, I just left them at the default values and it worked fine. Unfortunately Mac/AppKit development (esp. when using IB) is rife with these kind of odd bugs and weird behaviour, probably because Apple has not given it any love in years, so bugs creep in/fester and they are clearly so DONE with developing UI the 'old fashioned way'. (Using SwiftUI to make a Mac app is just as frustrating, in different ways, so I'll stick with what I know). FYI, I used Xcode 13.4.1 to create this test project. Good luck!

Launching OS X application in screen center

This seems like a very basic question, but I couldn't find the answer anywhere. How do I launch my non-resizable OS X application window in the center of the screen?
If you select your top level window, the Size Inspector will show you a screen similar to this
You can then drag the representation of your window to where you want it to be positioned when launched, or set the specific coordinates.
You can choose the center position for the window in Interface Builder by choosing the size inspector. Otherwise you can call [window center] in applicationDidFinishLaunching

How to show popover only in window bounds?

Button which show the popover lay on the button left corner of window.
How to show popover only in window bounds?
Attention! Mac OS.
This is not possible. NSPopover is a floating window that is connected to a certain other window but otherwise stays completely on its own. You can however try manually to keep it within certain bounds on screen by calculating a popup position that keeps the popover bounds with that area. But this won't work in all cases anyway (e.g. if the user moves the app window so that there's simply not enough room for the popover).

How to resize controls to fit the browser window in C#, Silverlight 4

I have a tab control in my main page. When I have it in the Design view in Visual Studio, everything looks perfect, the tab control is set to fill the entire page. However when I run the program, and I have it in a maximized browser window, the tab control is still the same size as it originally was. In other words, the tab control does not resize proportionally to the browser window resize.
So I was wondering if there was a way to change a setting on my tab control or maybe some code that would force the tab control to resize along with the browser window?
(Using C#, Silverlight 4.0 in VS2010)
Ok, so after tinkering with this for the last couple days, I've finally found the answer. I feel like a rookie for not doing this sooner, but I got to looking at the title bar on the top of the page and noticed that it stretched across the screen when the browser window was maximized and when it was resized, the title bar shrunk to fit. So I looked at the properties of the title bar and saw that it's horizontal/vertical alignment was set to "stretch." I know, it's a rookie mistake, but it just never occurred to me that "stretch" was an option in the alignment property.
Long story short, change the horizontal alignment property to "stretch," vertical alignment property to "stretch," and then set the height property of the control to "auto" and the width property to "auto" and you've got yourself an auto-resized control.

Preserving window position in Interface Builder

Is there a way to preserve window position in Interface Builder? Every time I reopen a nib file, the MainWindow.xib window finds its way back to the top left of the screen, behind the window containing the interface I'm laying out. Moving it back to where I had it before every time is starting to get on my nerves. Seems like there should be an easy way to do this, but if there is I haven't been able to find it.
Thanks!
Interface Builder does not save window location/size on a per-nib basis, but it does automatically remember the size and position of the last nib window and uses that when opening future nib files. For example, if I open up nib file A, change its window's position, and then quit IB, then open up nib file B, its nib window shows up with the same location/size I had set for nib file A.
However, it appears that Interface Builder also cascades multiple windows down and to the right slightly when you open them up, so that a second nib file's window doesn't appear directly on top of one that's already open - makes sense. The problem appears to be that if you have a nib window positioned all the way at the bottom of the screen, so there's not enough room to open the next nib window, it results in the window being placed all the way at the top of the screen. Then of course once that happens, IB remembers that window position as the default, so subsequent windows also get opened at the top of the screen.
So, the "solution" is a) file an enhancement request on Bug Reporter to remember per-nib window positions :-), and b) in the meantime be careful about positioning your windows too close to the bottom of the screen.

Resources