Last active
November 28, 2018 08:32
-
-
Save 623637646/2962d16fcb8fcab723d538c7016931f1 to your computer and use it in GitHub Desktop.
Get UIImage by name in framework
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
#define UIImageWithName(IMAGE_NAME)\ | |
(^UIImage *(NSString *imageName){\ | |
NSAssert(imageName.length != 0, @"imageName is empty");\ | |
if (imageName.length == 0) {\ | |
return nil;\ | |
}\ | |
NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle bundleForClass:NSClassFromString(@"SHPUIModule")] pathForResource:@"SHPUIKit" ofType:@"bundle"]];\ | |
NSAssert(bundle != nil, @"bundle is nil");\ | |
if (bundle == nil) {\ | |
return nil;\ | |
}\ | |
UIImage *image = [UIImage imageNamed:imageName inBundle:bundle compatibleWithTraitCollection:nil];\ | |
NSAssert(image != nil, @"image is nil");\ | |
if (image == nil) {\ | |
return nil;\ | |
}\ | |
return image;\ | |
}(IMAGE_NAME)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment