Short and sweet: How can I tell Interface Builder to center a window on a user's screen? I've seen the positioning tool on the inspector, but eyeballing doesn't always land as squarely as I like. Is this something where I should switch over to Xcode and add something to the init
or awakeFromNib
methods?
相关问题
- NSOutlineView drag line stuck + blue border
- iphone sdk see size of local file (one created
- How can you detect the connection and disconnectio
- QuickLook Plugin Failing with sandboxing error
- NSTextField font styling resets when selected
相关文章
- Xcode: Is there a way to change line spacing (UI L
- Converting (u)int64_t to NSNumbers
- “getter” keyword in @property declaration in Objec
- NSMenuItem KeyEquivalent “ ”(space) bug
- Why are my UIView layer properties not being set w
- Quit app when NSWindow closes
- CSS margin auto not centering
- Detect if cursor is hidden on Mac OS X
In your appdelegate, in applicationfinishedlaunching, add this code at the bottom.
Use
[window center];
for the centre of the window to be centred to the screen. Also, assuming you're in 10.5+ , there is a centre to screen button in InterfaceBuilderFor macOS Mojave this worked for me, in
AppDelegate
applicationDidFinishLaunching
for the Main Window:You could use
[window center]
as answered by wahkiz, but that might not be exactly what you want. The documentation states that this will put the window centered horizontally, but somewhat above the vertical centre. In this way the window has a visual prominence.If you want to put your window in the exact centre, then manual positioning (as commented by Koning Baard XIV) will work for you.