Posts

Showing posts from March 19, 2019

Programmatically get screen size in Mac OS X

Image
29 10 I am able to return the screen size using: - (void) getScreenResolution NSArray *screenArray = [NSScreen screens]; NSScreen *mainScreen = [NSScreen mainScreen]; unsigned screenCount = [screenArray count]; unsigned index = 0; for (index; index < screenCount; index++) NSScreen *screen = [screenArray objectAtIndex: index]; NSRect screenRect = [screen visibleFrame]; NSString *mString = ((mainScreen == screen) ? @"Main" : @"not-main"); NSLog(@"Screen #%d (%@) Frame: %@", index, mString, NSStringFromRect(screenRect)); Output: Screen #0 (Main) Frame: 0, 4, 1344, 814 Is there a way to format 1344, 814 to 1344x814 ? Edit: This works perfectly: - (NSString*) screenResolution NSRect screenRect; NSArray *screenArray = [NSScreen screens]; unsigned screenCount = [screenArray count]; unsigned index = 0; for (index; index < screenCount; index++) NSScreen *screen = [screenArray objectAtIndex: index]; screenRect = [screen visib...