加载自定义bundle中资源

2018-04-19  本文已影响0人  娜娜的世界123

bundle 存储资源(图片、xib、storyboard)

加载bundle有很多方式

.a静态库加载

NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"MNMediatorDemo" ofType:@"bundle"]]; 
NSString *alertImagePath = [bundle pathForResource:@"apple.png" ofType:nil];

self.imgView.image = [UIImage imageWithContentsOfFile:alertImagePath];

动态库加载方式

NSBundle *b = [NSBundle bundleForClass:[self class]];
NSString *path = [b pathForResource:@"MNMediatorDemo.bundle" ofType:nil];
NSString *imgPath = [[NSBundle bundleWithPath:path] pathForResource:@"apple.png" ofType:nil];

self.imgView.image = [UIImage imageWithContentsOfFile:imgPath];

上一篇 下一篇

猜你喜欢

热点阅读