Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get size of nswindow

Is there any way I get get the size of an NSWindow (in pixels) and display it? So when the person resizes the window the text will change and display the new size.

like image 589
Matt S. Avatar asked Sep 03 '09 16:09

Matt S.


3 Answers

If you implement the method

- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize

on an object you set as the delegate of the window, it will be called whenever the window changes size. From there you can update the text field you use for displaying the size.

like image 136
Ken Avatar answered Sep 21 '22 22:09

Ken


What about:

CGSize window_size = my_window.frame.size;
like image 30
fbrereto Avatar answered Sep 21 '22 22:09

fbrereto


NSSize myNSWindowSize = [ [ myNSWindow contentView ] frame ].size;

...should be what you're looking for. fbrereto's suggestion is what you should use if you want the size including the NSWindow's title bar.

like image 3
Ted Middleton Avatar answered Sep 21 '22 22:09

Ted Middleton