5

I am newbie in objective-c.I have created a main window which I want to display in the right bottom of the current screen. I tried the following code

- (void)windowDidLoad
{
    NSPoint pos;

    pos.x = [[NSScreen mainScreen] visibleFrame].origin.x + [[NSScreen mainScreen] visibleFrame].size.width - [mywindow frame].size.width ;

    pos.y = [[NSScreen mainScreen] visibleFrame].origin.y + [[NSScreen mainScreen] visibleFrame].size.height - [mywindow frame].size.height;

    [mywindow setFrameTopLeftPoint:pos];

}

what is wrong with in it? How to resolve it?

boopathy
  • 427
  • 2
  • 9
  • 20

1 Answers1

6

Use

NSPoint pos; 
pos.x = [[NSScreen mainScreen] frame].size.width - [mywindow frame].size.width ;

pos.y = 0.0f;

[self.window setFrame:CGRectMake(pos.x, pos.y, [mywindow frame].size.width , [mywindow frame].size.height) display:YES];

Because [[NSScreen mainScreen] frame].origin.x will always be 0. And in case of mac screen starts from bottom.

Yogendra
  • 1,728
  • 16
  • 28
  • 7
    This actually isn't true, `mainScreen` is the screen that has the mainWindow; which may or may not be the screen that has an x origin of 0. The origin screen (the one that contains 0,0, is `[[NSScreen screens] firstObject]` – rudy Nov 08 '17 at 20:46