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
?
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 visibleFrame];
}
return [NSString stringWithFormat:@"%.1fx%.1f",screenRect.size.width, screenRect.size.height];
}
Finding the screen size in Mac OS is very simple:
NSRect e = [[NSScreen mainScreen] frame];
H = (int)e.size.height;
W = (int)e.size.width;