Skip to content

Instantly share code, notes, and snippets.

@Shilo
Created November 7, 2011 23:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shilo/1346532 to your computer and use it in GitHub Desktop.
Save Shilo/1346532 to your computer and use it in GitHub Desktop.
A Sparrow category that allows support for iPad resolution.
//
// 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