编译完的mainbundle 和 currentbundle 文件位置
图中的 Images.xcassets 就是日常 xcode 中的存放图片的位置
图中的 QGTool.bundle 就是日常 QGTool/Assets的位置
在文件夹中的xib 和图片的层级显示
1.在 cocoapod 使用 xib 资源
在 cocoapod 中使用 xib 因为编译运行后 cocoapod 中的 bundle 不在 mianBundle 中 所以使用方式略有不同
// - cocoapod 中使用bundle
NSBundle *currentBundle = [NSBundle bundleForClass:[self class]];
MyView *view = [[currentBundle loadNibNamed:@"MyView" owner:nil options:nil]lastObject];
// - 正常的项目中使用 bundle
NSBundle *mainBundle = [NSBundle mainBundle];
MyView *view = [[mainBundle loadNibNamed:@"MyView" owner:nil options:nil]lastObject];
2.在 cocoapod 使用图片资源
在 cocoapod 中使用图片 因为编译运行后 cocoapod 中的 bundle 不在 mianBundle 中 所以使用方式略有不同 所以图片的位置也不同
2.1 修改 spec 文件
2.2 在 xib 中使用图片资源的写法是 在图片名称的位置填写图片名称 : QGTool.bundle/btn_dm_bottom_select
在 code 中使用图片资源的写法是 (code 中需要加上@2x)
NSString *path = [currentBundle pathForResource:@"defaultCategoryLogo@2x" ofType:@"png" inDirectory:@"QGTool.bundle"];
view.imageView2.image = [UIImage imageWithContentsOfFile:path];
注意 : image 在未编译时候在 pod 中的路径是 QGTool/Assets/images
但是我们在项目中写的路径是 QGTool.bundle/btn_dm_bottom_select