Created
August 9, 2015 13:31
-
-
Save yimingtang/04ac9ff730e8ee82c1ee to your computer and use it in GitHub Desktop.
UIImage+MyLibrary
This file contains 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
// | |
// UIImage+MyLibrary.m | |
// | |
// Created by Yiming Tang on 7/9/15. | |
// Copyright (c) 2015 Yiming Tang. All rights reserved. | |
// | |
@import UIKit; | |
@interface UIImage (MyLibrary) | |
+ (UIImage *)my_bundleImageNamed:(NSString *)name; | |
@end |
This file contains 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
// | |
// UIImage+MyLibrary.m | |
// | |
// Created by Yiming Tang on 7/9/15. | |
// Copyright (c) 2015 Yiming Tang. All rights reserved. | |
// | |
#import "UIImage+MyLibrary.h" | |
#import "NSBundle+MyLibrary.h" | |
@implementation UIImage (MyLibrary) | |
+ (UIImage *)my_bundleImageNamed:(NSString *)name { | |
return [self my_imageNamed:name inBundle:[NSBundle my_myLibraryBundle]]; | |
} | |
+ (UIImage *)my_imageNamed:(NSString *)name inBundle:(NSBundle *)bundle { | |
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_8_0 | |
return [self imageNamed:name inBundle:bundle compatibleWithTraitCollection:nil]; | |
#elif __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_8_0 | |
return [self imageWithContentsOfFile:[bundle pathForResource:name ofType:@"png"]]; | |
#else | |
if ([self respondsToSelector:@selector(imageNamed:inBundle:compatibleWithTraitCollection:)]) { | |
return [self imageNamed:name inBundle:bundle compatibleWithTraitCollection:nil]; | |
} else { | |
return [self imageWithContentsOfFile:[bundle pathForResource:name ofType:@"png"]]; | |
} | |
#endif | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment