ios开发之使用bundle来管理资源文件

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

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

使用最简单的方法创建一个bundle:

1 创建一个文件夹

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

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

这样处理之后,取图片之类的文件,使用的方法就不一样了,以取iphone_52x52.png图片为例:

        NSString *bundlePath = [[NSBundle mainBundle].resourcePath stringByAppendingPathComponent:@"My.bundle"];

        NSBundle *bundle = [NSBundle bundleWithPath:bundlePath];

        UIImage *(^getBundleImage)(NSString *) = ^(NSString *n) {

            return [UIImage imageWithContentsOfFile:[bundle pathForResource:n ofType:@"png"]];

        };

        UIImage *myImg = getBundleImage(@"iphone_52x52");

原文地址:https://www.cnblogs.com/417460188dy/p/3584671.html