Xcode 7 Framework中图片资源,打包bundle
2015-12-29 20:53
309 查看
打包bundle文件
1、新建OS X->Framework & Library->Bundle新建
2、在Build Settings->(null)-Deployment->iOS Deployment Target->选择自己需要支持的最低系统。
3、build后会生成一个bundle包,但在包中的图片由以前的png格式全部变成tiff格式。为了防止这种格式转变。需要在Build Settings->Architectures->Base SDK->选择iOS的SDK要支持的版本。这时TARGETS中Build Setting->User-Defined中会出现一个新的Key:COMBINE_HIDPI_DEBUG_INFO,把它设置为NO。
4、这样创建的图片资源不能使用[UIImage imageNamed:@“png”]来获取了。需要使用路径方式来读取图片。
这里我使用了一个函数来获取路径。
NSString *getKaYiKaImageBundlePath(NSString *filename);
NSString *getKaYiKaImageBundlePath(NSString *filename) {
NSBundle *libBundle = [NSBundle bundleWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"KaYiKa.bundle"]];
if (libBundle && filename) {
NSString *path = [[libBundle resourcePath] stringByAppendingPathComponent:filename];
path = [path stringByAppendingString:@".png"];
return path;
}
return nil;
}
使用时直接用
[UIImage imageWithContentsOfFile:getKaYiKaImageBundlePath(@"tool_return_day")]获取图片。
直接导出方法:
1.添加 target --> other -->aggregate
2.在新建的Target里边添加一个脚本:Build Phases -->new Run Script Phase
3.填入下面脚本到 Run Script
# begin =============================================
# Sets the target folders and the final framework product.
# 如果工程名称和Framework的Target名称不一样的话,要自定义FMKNAME
# 例如: FMK_NAME = "MyFramework"
FMK_NAME=${PROJECT_NAME}
# Install dir will be the final output to the framework.
# The following line create it in the root folder of the current project.
INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.bundle
# Working dir will be deleted after the framework creation.
WRK_DIR=build
DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.bundle
SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.bundle
# -configuration ${CONFIGURATION}
# Clean and Building both architectures.
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos -arch armv7 -arch armv7s -arch arm64 clean build
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator -arch x86_64 clean build
# Cleaning the oldest.
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
mkdir -p "${INSTALL_DIR}"
cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"
# Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.
lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}"
rm -r "${WRK_DIR}"
open "${SRCROOT}/Products/"
# end ===============================================
1、新建OS X->Framework & Library->Bundle新建
2、在Build Settings->(null)-Deployment->iOS Deployment Target->选择自己需要支持的最低系统。
3、build后会生成一个bundle包,但在包中的图片由以前的png格式全部变成tiff格式。为了防止这种格式转变。需要在Build Settings->Architectures->Base SDK->选择iOS的SDK要支持的版本。这时TARGETS中Build Setting->User-Defined中会出现一个新的Key:COMBINE_HIDPI_DEBUG_INFO,把它设置为NO。
4、这样创建的图片资源不能使用[UIImage imageNamed:@“png”]来获取了。需要使用路径方式来读取图片。
这里我使用了一个函数来获取路径。
NSString *getKaYiKaImageBundlePath(NSString *filename);
NSString *getKaYiKaImageBundlePath(NSString *filename) {
NSBundle *libBundle = [NSBundle bundleWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"KaYiKa.bundle"]];
if (libBundle && filename) {
NSString *path = [[libBundle resourcePath] stringByAppendingPathComponent:filename];
path = [path stringByAppendingString:@".png"];
return path;
}
return nil;
}
使用时直接用
[UIImage imageWithContentsOfFile:getKaYiKaImageBundlePath(@"tool_return_day")]获取图片。
直接导出方法:
1.添加 target --> other -->aggregate
2.在新建的Target里边添加一个脚本:Build Phases -->new Run Script Phase
3.填入下面脚本到 Run Script
# begin =============================================
# Sets the target folders and the final framework product.
# 如果工程名称和Framework的Target名称不一样的话,要自定义FMKNAME
# 例如: FMK_NAME = "MyFramework"
FMK_NAME=${PROJECT_NAME}
# Install dir will be the final output to the framework.
# The following line create it in the root folder of the current project.
INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.bundle
# Working dir will be deleted after the framework creation.
WRK_DIR=build
DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.bundle
SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.bundle
# -configuration ${CONFIGURATION}
# Clean and Building both architectures.
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos -arch armv7 -arch armv7s -arch arm64 clean build
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator -arch x86_64 clean build
# Cleaning the oldest.
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
mkdir -p "${INSTALL_DIR}"
cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"
# Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.
lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}"
rm -r "${WRK_DIR}"
open "${SRCROOT}/Products/"
# end ===============================================
相关文章推荐
- API & SPI
- akka---Getting Started Tutorial (Java): First Chapter
- 高精度乘法程序
- Java 中4字节形式数据转换为float
- linux系统启动流程
- android性能优化
- 让OpenCV枚举所有摄像头-附如何建立Windows下的OpenCV工程
- 20151229--数据表格
- SQL学习总结
- android 日历源码
- epoll详解
- PhoneGap/Cordova学习笔记--4.使用HTML5进行页面布局
- 高并发,高性能的一点调研
- 数据迁移程序
- C#难点逐个击破3params数组参数
- Spring Scope讲解
- 作品第二课----基于bootstrap的滚动监听
- 学习笔记 --- 最大流Dinic算法
- 课程设计——图书管理新系统
- (⊙o⊙)…