Skip to content

Instantly share code, notes, and snippets.

@yimingtang
Created August 9, 2015 13:31
Show Gist options
  • Save yimingtang/04ac9ff730e8ee82c1ee to your computer and use it in GitHub Desktop.
Save yimingtang/04ac9ff730e8ee82c1ee to your computer and use it in GitHub Desktop.
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