Reputation: 744
I'm writing a class to build a cocoapods and I want to get the image I placed in Assets.xcassets
. The problem is always getting nil
image. Are there anything I miss?
Here is the directory stucture :
This is what I try to load the Image:
#import "HaloImage.h"
@implementation HaloImage
- (void)showImage {
NSBundle * bundle = [NSBundle bundleForClass:self];
NSURL * bundleUrl = [bundle URLForResource:@"Assets" withExtension:@"bundle"];
self.image = [UIImage imageNamed:bundleUrl.absoluteString];
}
@end
Upvotes: 3
Views: 3228
Reputation: 482
You can access image from Assets.xcassets by this. Give it a try
UIImage *image = [UIImage imageNamed:@"image name without extension"];
Upvotes: 2
Reputation: 392
Can you please try below code :
@implementation HaloImage
- (void)showImage {
NSBundle * bundle = [NSBundle bundleForClass:self];
NSURL * bundleUrl = [bundle pathForResource:@"Assets" withExtension:@"bundle"];
self.image = [UIImage imageNamed:bundleUrl.absoluteString];
}
@end
Upvotes: 0
Reputation: 878
you can use image from asset or main bundle only by name (png file)
self.image = [UIImage imageNamed:@"name_of_image"];
Upvotes: 0