Created
December 18, 2014 02:07
-
-
Save nicolas-miari/0414af079e784f73a7ce to your computer and use it in GitHub Desktop.
Extracts the scale factor (e.g. 1x, 2x, 3x) of an image file name as a float.
This file contains hidden or 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
- (CGFloat) imageScaleFactorFromFilename:(NSString*) imageFileName | |
{ | |
NSString* filename = [imageFileName stringByDeletingPathExtension]; | |
NSArray* components = [filename componentsSeparatedByString:@"@"]; | |
if ([components count] > 1) { | |
// Hi res image | |
NSString* scaleSubstring = [components objectAtIndex:1]; // e.g. @"2x" | |
scaleSubstring = [scaleSubstring stringByReplacingOccurrencesOfString:@"x" withString:@""]; | |
CGFloat scaleFactor = [scaleSubstring floatValue]; | |
return scaleFactor; | |
} | |
return 1.0f; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment