iOS打包图片资源为Bundle

本文详细介绍了如何在MacOS环境下通过Xcode新建工程并配置参数来创建iOS Bundle资源包,包括设置BaseSDK、BuildActiveArchitectureOnly、InstallationDirectory等关键步骤,以及如何将图片资源拖入工程和编译生成bundle,最后提供了两种使用生成的bundle资源的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值