Skip to content

Instantly share code, notes, and snippets.

@623637646
Last active November 28, 2018 08:32
Show Gist options
  • Save 623637646/2962d16fcb8fcab723d538c7016931f1 to your computer and use it in GitHub Desktop.
Save 623637646/2962d16fcb8fcab723d538c7016931f1 to your computer and use it in GitHub Desktop.
Get UIImage by name in framework
#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