Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.