Created
November 7, 2011 23:28
-
-
Save Shilo/1346532 to your computer and use it in GitHub Desktop.
A Sparrow category that allows support for iPad resolution.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Sparrow+SupportPadResolution.h | |
// UniversalTextureTest | |
// | |
// Created by Shilo White on 11/7/11. | |
// Copyright (c) 2011 Shilocity Productions. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
#import "SPStage.h" | |
#import "SPUtils.h" | |
static BOOL sSupportPadResolutions = NO; | |
static NSString *sPadResolutionsSuffix = @"@hd"; | |
@interface SPStage (PrivateMethods) | |
+ (void)updateNativeViews; | |
@end | |
@interface SPStage (SupportPadResolution) | |
+ (void)setSupportPadResolutions:(BOOL)supportPadResolutions; | |
+ (BOOL)supportPadResolutions; | |
@end | |
@implementation SPStage (SupportPadResolution) | |
+ (void)setSupportPadResolutions:(BOOL)supportPadResolutions { | |
if (supportPadResolutions != sSupportPadResolutions) { | |
sSupportPadResolutions = supportPadResolutions; | |
[SPStage updateNativeViews]; | |
} | |
} | |
+ (BOOL)supportPadResolutions { | |
return sSupportPadResolutions; | |
} | |
@end | |
@interface SPUtils (SupportPadResolution) | |
+ (BOOL)isDevicePad; | |
@end | |
@implementation SPUtils (SupportPadResolution) | |
+ (BOOL)isDevicePad { | |
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad); | |
} | |
+ (NSString *)absolutePathToFile:(NSString *)path withScaleFactor:(float)factor { | |
NSString *absolutePath = [path isAbsolutePath] ? path : [[NSBundle appBundle] pathForResource:path]; | |
if (factor != 1.0f) { | |
NSString *suffix = [NSString stringWithFormat:@"@%@x", [NSNumber numberWithFloat:factor]]; | |
NSString *pathWithScale = [absolutePath stringByAppendingSuffixToFilename:suffix]; | |
if ([SPUtils fileExistsAtPath:pathWithScale]) return pathWithScale; | |
} else if ([self isDevicePad] && [SPStage supportPadResolutions]) { | |
NSString *pathWithPadResolution = [absolutePath stringByAppendingSuffixToFilename:sPadResolutionsSuffix]; | |
if ([SPUtils fileExistsAtPath:pathWithPadResolution]) return pathWithPadResolution; | |
} | |
if ([SPUtils fileExistsAtPath:absolutePath]) | |
return absolutePath; | |
else | |
return nil; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment