您的位置:首页 > 其它

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

2016-05-04 19:38 387 查看
封装.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 内



分别声称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 中找

这样就可以了!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息