Centering Windows on screen

怎甘沉沦 提交于 2019-12-05 07:27:06

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.

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 InterfaceBuilder

In your appdelegate, in applicationfinishedlaunching, add this code at the bottom.

[window center];

For macOS Mojave this worked for me, in AppDelegate applicationDidFinishLaunching for the Main Window:

[[[NSApplication sharedApplication] mainWindow] center];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!