私有库的资源依赖和图片依赖

1,219 阅读1分钟

xib文件依赖

当加载私有库中的xib文件时,会报错:

Could not load NIB in bundle: 'NSBundle </Users/lizan/Library/Developer/CoreSimulator/Devices/7B97CBF6-6B0E-44DA-BA93-8C49E7339CBD/data/Containers/Bundle/Application/920E37F9-7A7B-4319-9D4B-18AB7A6A129D/LZBase2_Example.app> (loaded)' with name 'Test1View''

mainBundle在上面的路径中

组件中生成的nib在

所以使用mianBundle找不到该资源.

解决办法:引用私有库中的xib时,定位到响应class的bundle再loadnib

NSBundle *bundle = [NSBundle bundleForClass:[Test1View class]];

Test1View *testView = [bundle loadNibNamed:@"Test1View" owner:nil options:nil].firstObject;


图片依赖

1.将需要的图片放入


文件夹中

2.放开spec文件中的


3.pod install  EXample文件  出现这个


4.在xib中设置图片:


前面bundle的路径在

中,右击找

复制LZBase3.bundle的全称即可.

如果修改了私有库本地代码不生效,则clearn一下.

5.在代码中运用image.

NSBundle *currentBundle = [NSBundle bundleForClass:[self class]];

NSString *pathStr = [currentBundle pathForResource:@"mainBUndle.png" ofType:nil inDirectory:@"LZBase3.bundle"];imageView.image = [UIImage imageWithContentsOfFile:pathStr];

待解决问题:

1.为什么两个图片,bundle中只引入一个?????????/创建完新项目也是一个