NSBundle 资源获取

2018-07-06  本文已影响10人  SamCheck

获取.bundle包中的资源

NSBundle *bundle = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"Resources" withExtension:@"bundle"]];

//获取的文件在bundle的根目录
NSString *resource = [bundle resourcePath];
//获取的文件在bundle的根目录中test/wss子目录中
resource = [bundle pathForAuxiliaryExecutable:@"test/wss"];

NSString *pngPath = [resource stringByAppendingPathComponent:@"ddddd.png"];

UIImage *img1 = [UIImage imageNamed: pngPath];//加载到缓存
UIImage *img2 = [UIImage imageWithContentsOfFile: pngPath];//只加载本地,不到缓存中
上一篇 下一篇

猜你喜欢

热点阅读