美文网首页
加载自定义bundle中资源

加载自定义bundle中资源

作者: 娜娜的世界123 | 来源:发表于2018-04-19 17:33 被阅读0次

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];

相关文章

网友评论

      本文标题:加载自定义bundle中资源

      本文链接:https://www.haomeiwen.com/subject/iqgwkftx.html