一、创建bundle
Xcode Version 9.4.1
1、工程里command+N创建文件,选择iOS下的Settings Bundle
2、命名并保存
3、点击已经创建的bundle文件,右键Show in Finder找到bundle文件,bundle文件右键显示包内容,然后添加需要的图片
4、工程里bundle文件下添加刚才的图片
二、使用bundle文件里的图片
1、调用方式一,PlayButton是图片名称
imageView
[imageView setImage:[UIImage imageNamed:@"Resource.bundle/Assets/PlayButton"]];
button
[button setImage:[UIImage imageNamed:@"Resource.bundle/Assets/PlayButton"] forState:UIControlStateNormal];
2、调用方式二
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"Resource" ofType:@"bundle"];
NSString *imgPath = [bundlePath stringByAppendingPathComponent:@"Assets/PlayButton"];
[button setImage:[UIImage imageWithContentsOfFile:imgPath] forState:UIControlStateNormal];
3、调用方式三
#define LYBundle_Name @"Resource.bundle/Assets"
#define LYBundle_Path [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:LYBundle_Name]
#define LYBundle [NSBundle bundleWithPath:LYBundle_Path]
[button setImage:[UIImage imageNamed:@"PlayButton" inBundle:LYBundle compatibleWithTraitCollection:nil] forState:UIControlStateNormal];