Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centering Windows on screen

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?

like image 317
Kaji Avatar asked Dec 06 '09 10:12

Kaji


2 Answers

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.

like image 109
Abizern Avatar answered Sep 19 '22 23:09

Abizern


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 Interface Builder.

like image 21
Alexandre Cassagne Avatar answered Sep 22 '22 23:09

Alexandre Cassagne