Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
UIImage+MyLibrary
//
// 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
//
// 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