您当前的位置: 首页 >  ios

培根芝士

暂无认证

  • 0浏览

    0关注

    446博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

iOS打包图片资源为Bundle

培根芝士 发布时间:2020-01-09 12:09:50 ,浏览量:0

1,新建工程,选择macOS->Bundle

2,选择Build Settings,修改以下配置:

"Base SDK" 设置为 "iOS "

"Build Active Architecture Only" 设置为 "YES" (Debug,Release均为YES)(仅编译当前环境,如果每个环境都编译一遍会使包变大)

Installation Directiotory    删除掉后面的路径 (不安装相关配置,也不需要安装路径)

Code Signing Identity   选择  "-" 

"iOS Deployment Target" 设置为 iOS 9.0  

"Skip Install" 设置为 "NO"  (不需要安装相关配置)

"Strip Debug Symbols During Copy" 中"Release"模式设置为 "YES"

"COMBINE_HIDPI_IMAGES" 设置为 "NO" (不然图片会是tiff格式)

 

3,将图片资源拖入到工程中,或者在Build Phases-Copy Bundle Resources中添加

4,编译生成bundle。

5,使用方式:

第一种:

UIImage *image = [UIImage imageNamed:@“animate.bundle/001.png"];

 

第二种:

NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"animate.bundle" ofType:nil];

NSBundle *imageBundle = [NSBundle bundleWithPath:bundlePath];

 

UIImage *image = [UIImage imageNamed:@"001" inBundle:imageBundle compatibleWithTraitCollection:nil];

或者

NSString *path = [imageBundle pathForResource:@"001" ofType:@"png"];

UIImage *image = [UIImage imageWithContentsOfFile:path];

关注
打赏
1660824269
查看更多评论
立即登录/注册

微信扫码登录

0.2669s