Skip to content

Instantly share code, notes, and snippets.

@nicolas-miari
Created December 18, 2014 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicolas-miari/0414af079e784f73a7ce to your computer and use it in GitHub Desktop.
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.
- (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