关于静态库添加图片资源的解决方案

封装.a 静态库
这里写图片描述
剩下的操作和动态更新差不多!可以参考我之前的一篇文章热更新FrameWork

创建bundle
只需要将图片资源放入一个文件夹如:imageSource
然后把后缀改成.bundle即可

使用资源图片

$ NSBundle *imageSourceBundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"imageSource" ofType:@"bundle"]]

拼接路径

 $ if (retainFllow5) {// 判断加载几倍图
       imageSuffix = [NSString stringWithFormat:@"%d@2x",n];
    } else {
       imageSuffix = [NSString stringWithFormat:@"%d@3x",n];
    }
$ NSString *mosaic = [NSString stringWithFormat:@"%@%@", imagePrefix, imageSuffix];
$ NSString *imageSource = [imageSourceBundle pathForResource:mosaic ofType:@"png"];

这里得到的就是你需要的图片资源

$ [UIImage imageWithContentsOfFile:imageSource]

将需要的头文件添加到publicGroup 内
生成.a
分别声称release 和debug 两个版本的.a 文件方便调试和 真机使用
将两个版本.a 合并
这里写图片描述

$ lipo -create /Users/chenwei/Desktop/XXX/debug/libPeopleKeybord.a /Users/chenwei/Desktop/XXX/release/libPeopleKeybord.a -output /Users/chenwei/Desktop/XXX/libPeopleKeybord.a

看下 你会发现1 就是lipo -create ……后的Path
2 就是1.a 空之后的Path
3 就是 -output 之后的Path
也就是 你需的合并后的.a 库

将.a 和bundle 同时放入同一工程一个文件下
.a需要用到的图片资源就会去.bundle 中找
这样就可以了!

猜你喜欢

转载自blog.csdn.net/github_34203934/article/details/51317526