1、创建bundle(超简便,即修改文件夹后缀)
将要使用的资源文件放到一个文件夹内,比如图片、视频、JSON文件等
2、使用bundle的好处
在一个程序中使用bundle,方便归类资源文件,图片放到一个bundle,JSON数据放到另外一个bundle,取数据的时候直接找到对应bundle,然后再找到对应的数据
3、如何使用
Demo:
UIImageView *imgView = [[UIImageView alloc]initWithFrame:self.view.bounds];
[self.view addSubview:imgView];
NSString *bundlePath = [[NSBundle mainBundle]pathForResource:@"SRC" ofType:@"bundle"];
NSBundle *resource = [NSBundle bundleWithPath:bundlePath];
imgView.image = [UIImage imageNamed:@"321" inBundle:resource compatibleWithTraitCollection:nil];
或者
UIImageView *imgView = [[UIImageView alloc]initWithFrame:self.view.bounds];
[self.view addSubview:imgView];
imgView.image = [UIImage imageNamed:@"SRC.bundle/321"];
4、注意事项
一定要先读取指定bundle,才能取到数据