我正在写一个类来构建一个cocoapods,我希望得到我放在Assets.xcassets
中的图像。问题始终是获得nil
图片。我有什么想念吗?
这是我尝试加载图片的内容:
#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
答案 0 :(得分:0)
您只能通过名称(png文件)使用资产或主要包中的图像
self.image = [UIImage imageNamed:@"name_of_image"];
答案 1 :(得分:0)
请试试下面的代码:
@implementation HaloImage
- (void)showImage {
NSBundle * bundle = [NSBundle bundleForClass:self];
NSURL * bundleUrl = [bundle pathForResource:@"Assets" withExtension:@"bundle"];
self.image = [UIImage imageNamed:bundleUrl.absoluteString];
}
@end
答案 2 :(得分:0)
您可以通过此访问Assets.xcassets中的图像。试一试
UIImage *image = [UIImage imageNamed:@"image name without extension"];