Bundle

iOS开发中为了方便管理资源文件,可以使用bundle的方式来进行管理,比如kkgridview里就是把所需的图片文件全部放在一个bundle来管理的 .

切记目前iOS中只允许使用bundle管理资源文件和国际化信息,不支持代码的打包。

在xcode中只能够创建setting bundle,会默认创建一些配置文件,在xcode中无法直接删除,这也许不是我们需要的。

那么如何使用最简单的方法创建一个bundle呢?

1 创建一个文件夹

2 将该文件夹重命名为a.bundle

3 将a.bundle拖入到xcode中即可

调用:

- (UIImage *)imagesNamedFromCustomBundle:(NSString *)imgName

{
    NSString *bundlePath=[[NSBundle mainBundle].resourcePath stringByAppendingPathComponent:@"sources.bundle"];
    
    NSBundle *bundle=[NSBundle bundleWithPath:bundlePath];
    
    NSString *imagePath =[[bundle resourcePath] stringByAppendingPathComponent:imgName];
    return [UIImage imageWithContentsOfFile:imagePath];
}
原文地址:https://www.cnblogs.com/sunjianfei/p/6693124.html