Skip to content

Instantly share code, notes, and snippets.

@sangregoriopaolo
Created September 3, 2012 12:54
Show Gist options
  • Save sangregoriopaolo/3609137 to your computer and use it in GitHub Desktop.
Save sangregoriopaolo/3609137 to your computer and use it in GitHub Desktop.
NSScreen+HighestDensity.h
#import <Cocoa/Cocoa.h>
@interface NSScreen (HighestDensity)
+ (CGFloat)highestDensity;
@end
#import "NSScreen+HighestDensity.h"
@implementation NSScreen (HighestDensity)
+ (CGFloat)highestDensity {
// Support for OSX 10.6
if (![[NSScreen mainScreen] respondsToSelector:@selector(backingScaleFactor)]) return 1.0f;
NSArray *screens = [NSScreen screens];
CGFloat highestDensity = 1.0f;
for (NSScreen *screen in screens) {
if ([screen backingScaleFactor] > highestDensity) {
highestDensity = [screen backingScaleFactor];
}
}
return highestDensity;
}
@end
#import "NSScreen+HighestDensity.h"
@implementation NSScreen (HighestDensity)
+ (CGFloat)highestDensity {
// Support for OSX 10.6
if (![[NSScreen mainScreen] respondsToSelector:@selector(backingScaleFactor)]) return 1.0f;
NSArray *screens = [NSScreen screens];
CGFloat highestDensity = 1.0f;
for (NSScreen *screen in screens) {
if ([screen backingScaleFactor] > highestDensity) {
highestDensity = [screen backingScaleFactor];
}
}
return highestDensity;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment