NSBundle+YYAdd.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // NSBundle+YYAdd.h
  3. // YYCategories <https://github.com/ibireme/YYCategories>
  4. //
  5. // Created by ibireme on 14/10/20.
  6. // Copyright (c) 2015 ibireme.
  7. //
  8. // This source code is licensed under the MIT-style license found in the
  9. // LICENSE file in the root directory of this source tree.
  10. //
  11. #import <Foundation/Foundation.h>
  12. #import <UIKit/UIKit.h>
  13. /**
  14. Provides extensions for `NSBundle` to get resource by @2x or @3x...
  15. Example: ico.png, ico@2x.png, ico@3x.png. Call scaledResource:@"ico" ofType:@"png"
  16. on iPhone6 will return "ico@2x.png"'s path.
  17. */
  18. @interface NSBundle (YYAdd)
  19. /**
  20. An array of NSNumber objects, shows the best order for path scale search.
  21. e.g. iPhone3GS:@[@1,@2,@3] iPhone5:@[@2,@3,@1] iPhone6 Plus:@[@3,@2,@1]
  22. */
  23. + (NSArray *)preferredScales;
  24. /**
  25. Returns the full pathname for the resource file identified by the specified
  26. name and extension and residing in a given bundle directory. It first search
  27. the file with current screen's scale (such as @2x), then search from higher
  28. scale to lower scale.
  29. @param name The name of a resource file contained in the directory
  30. specified by bundlePath.
  31. @param ext If extension is an empty string or nil, the extension is
  32. assumed not to exist and the file is the first file encountered that exactly matches name.
  33. @param bundlePath The path of a top-level bundle directory. This must be a
  34. valid path. For example, to specify the bundle directory for a Mac app, you
  35. might specify the path /Applications/MyApp.app.
  36. @return The full pathname for the resource file or nil if the file could not be
  37. located. This method also returns nil if the bundle specified by the bundlePath
  38. parameter does not exist or is not a readable directory.
  39. */
  40. + (NSString *)pathForScaledResource:(NSString *)name ofType:(NSString *)ext inDirectory:(NSString *)bundlePath;
  41. /**
  42. Returns the full pathname for the resource identified by the specified name and
  43. file extension. It first search the file with current screen's scale (such as @2x),
  44. then search from higher scale to lower scale.
  45. @param name The name of the resource file. If name is an empty string or
  46. nil, returns the first file encountered of the supplied type.
  47. @param ext If extension is an empty string or nil, the extension is
  48. assumed not to exist and the file is the first file encountered that exactly matches name.
  49. @return The full pathname for the resource file or nil if the file could not be located.
  50. */
  51. - (NSString *)pathForScaledResource:(NSString *)name ofType:(NSString *)ext;
  52. /**
  53. Returns the full pathname for the resource identified by the specified name and
  54. file extension and located in the specified bundle subdirectory. It first search
  55. the file with current screen's scale (such as @2x), then search from higher
  56. scale to lower scale.
  57. @param name The name of the resource file.
  58. @param ext If extension is an empty string or nil, all the files in
  59. subpath and its subdirectories are returned. If an extension is provided the
  60. subdirectories are not searched.
  61. @param subpath The name of the bundle subdirectory. Can be nil.
  62. @return The full pathname for the resource file or nil if the file could not be located.
  63. */
  64. - (NSString *)pathForScaledResource:(NSString *)name ofType:(NSString *)ext inDirectory:(NSString *)subpath;
  65. @end