Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

satyam90

macrumors regular
Original poster
Jul 30, 2007
242
0
Bangalore, India
Using Cocoa with Obj C and XCode 2.4.1
I created preferences window for my application. Its working fine. But I want to centre it every time it is displayed. I tried to position it at centre point thru show inspector of Interface builder. Still I couldn't. Need some help to centre the window.

Satya.
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
Western US
Using Cocoa with Obj C and XCode 2.4.1
I created preferences window for my application. Its working fine. But I want to centre it every time it is displayed. I tried to position it at centre point thru show inspector of Interface builder. Still I couldn't. Need some help to centre the window.
Call [myWindow center] on it when it's displayed. If you aren't the one controlling when it gets shown (by invoking a call on it directly that makes it visible), put the call inside a delegate method, such as perhaps windowDidBecomeMain: or windowDidExpose:
 

elppa

macrumors 68040
Nov 26, 2003
3,233
151
In another language, what I'd do is this:

[1] Take the width and the height of the users screen.
[2] Divide both by 2 to get a midpoint.
[3] Get the width and height of the window and half it.
[4] Offset it by the values collected in step 3 from the midpoint.

Sounds like Apple have a nifty shortcut though from the above poster.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
In another language, what I'd do is this:

[1] Take the width and the height of the users screen.
[2] Divide both by 2 to get a midpoint.
[3] Get the width and height of the window and half it.
[4] Offset it by the values collected in step 3 from the midpoint.

And then test it on a system with two monitors.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
I have a sharedinstance method which will return the instance of window and i am using
[[myWindow sharedInstance] center]
Still it is not working.

Make sure you're calling it after it's been initialized and awakeFromNib is called.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.