Grant Wilkinson
Grant Wilkinson

Reputation: 1128

NSRect Size to Fill Screen

How do i get the current size of the screen no matter the resolution change in xcode so that i can adjust my NSRect size to be maximized or take up the screen according to the resolution ? What do I need to add? Would it be something to the NSWindow?

 NSRect panelRect = [[self window] frame];
    panelRect.size.height = _HEIGHT;
    panelRect.size.width = _WIDTH;
    panelRect.origin.x = 0;
    panelRect.origin.y = 0;
    [[self window] setFrame:panelRect display:NO];

Thanks!

Upvotes: 3

Views: 1630

Answers (2)

TheAmateurProgrammer
TheAmateurProgrammer

Reputation: 9392

Have you tried using [[NSScreen mainScreen] frame]? If you want to exclude the menubar, you can subtract the menubar height from the NSRect's height. (It's around 20 pixels)

Edit: If you want your window to be resized from the start, you can put the method above in your controller's awakeFromNib and use NSWindow's setFrame:display: to resize it.

Upvotes: 1

rob mayoff
rob mayoff

Reputation: 385660

You can use CGDisplayBounds, which returns a CGRect containing the screen's bounds (origin and size) in global coordinates.

You can use CGDisplayRegisterReconfigurationCallback to be notified when a display configuration changes, which includes when its resolution is changed.

Quartz Display Services Reference

Upvotes: 3

Related Questions