Get size nswindow

Is there a way to get the NSWindow size (in pixels) and display it? Therefore, when the user resizes the window, the text will change and display the new size.

+6
cocoa size nswindow
source share
4 answers

If you implement a method

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

on the object that you set as the window delegate, it will be called whenever the window is resized. From there, you can update the text box that you use to display the size.

+12
source share

What about:

 CGSize window_size = my_window.frame.size; 
+5
source share
 NSSize myNSWindowSize = [ [ myNSWindow contentView ] frame ].size; 

... should be what you are looking for. The fbrereto clause is what you should use if you want size, including the NSWindow title bar.

+2
source share

Instead of trying to handle resizing, you should instead make sure that the autoresist masks of your views are set correctly. In Interface Builder, you do this in the size inspector (⌘3) with the selected views.

If you have selected the entire hierarchy of views without setting your autoresist masks, you have a little boredom ahead, but this is not difficult (just tedious) and will not take much time. This is why you should automatically configure view masks when you create them.

After setting auto-masks, the views will automatically resize; if your interface is not very complex, or any views can go down to size zero, you do not need to interfere.

0
source share

All Articles