zoukankan      html  css  js  c++  java
  • bundle 的生成和使用

    一、bundle 的生成

    1、打开XCode,创建iOS版用的bundle资源包,有两种方式:第一种直接将工作,open in  finder.在目录中直接新建文件夹,文件夹以bundle格式。文件夹就会变成通用的Bundle包样式。如此可以看出来bundle其实就是一个文件夹,与文件夹的操作相同。第二种方式是在主目录中,New file...选择iOS-》Resource-》Settings Bundle.

    第三种方式,在framework里集成bundle.详见图。选择OS X 的Bundle。因为Xcode7中iOS里没有Bundle.通过修改bundle的属性来试用iOS。

    2、在工程里添加你需要的内容 如图片资源等.目录束里面的xib,图片资源等,会自动收录到bundle文件夹中。

    3、选择debug 或 release 条件编译Bundle

    二、bundle 的使用

    1、将制作好的bundle拖曳至项目中

    2、使用Bundle中的资源

    UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(50, 50, 200, 200      )];

        NSString *bundlePath =[[NSBundle mainBundle]pathForResource:@"pictureBundle" ofType:@"bundle"];

        NSString *picturrePath =[bundlePath stringByAppendingPathComponent:@"Contents/Resources/fbb01.jpg"];

        UIImage *image =[UIImage imageWithContentsOfFile:picturrePath];

        imageView.image = image;

        [self.view addSubview:imageView];

    3、编译工程后,经验证成功使用了bundle中的资源。

     

    Xcode7.3 制作通用的framework 原文地址

    http://www.jianshu.com/p/0fed418f228c#

    1.新建一个工程.
    file→ new→ project, 弹出框中选择iOS→ framework & library中的cocoa touch framework.点击Next,输入product name: TestFramework, 点击Next→ 点击Create.
    2.删除向导所生成工程中的Target.

    点击工程名→ 点击TARGETS → 右键Delete.

    3.增加一个新的Target.

    点击Target底部的"+"号,弹出框中选择OS X→ Framework & Library中的Bundle.点击Next,输入product name TestFramework, 点击Finish.

    4.修改新建 Target 的 Building Settings 项.

    a: 选中TARGET→ Build Settings项, 将Architectures→ Base SDK 改为Latest iOS(iOS 9.0), 将Architectures 改为 $(ARCHS_STANDARD);

    b: 在 Deployment项, 选中"Mac OS X Deployment Target", 点击键盘上的Delete键, 将“Targeted Device Family”改成"1,2";

    c: 在 (null) - Deployment项, 修改"iOS Deployment Target"为"6.0",同时修改PROJECT的info下的Deployment Target → "iOS Deployment Target"为"6.0";

    d: 在Linking项, 将"Dead Code Stripping" 改为"NO", "Link With Standard Libraries" 改为 "NO", 将 "Mach-O Type" 改为"Relocatable Object File";

    f: 在Packing项, 将"Wrapper Extension" 改为 "framework";

    5.修改 Target 的 Info 项.

    点击Info, 将 "Bundle OS Type code" 改为 "FMWK"

    6.将要写入源码文件拖入工程目录, 这里以一个简单的语句输出作为例子

    Command+N 新建一个cocoa Touch class, 名字为TestLog, 点击Next, 点击create;

    TestLog.h代码如下:

    ​#import <Foundation/Foundation.h>
    @interface TestLog : NSObject

    • (void)TestLog;
      @end

    TestLog.m代码如下:

    import "TestLog.h"

    @implementation TestLog

    • (void)TestLog
      {
      NSLog(@"这里是静态库输出日志 ");
      }
      @end

    7.删除TestFramework.m, 修改TestFramework.h内容如下:

    ifndef TestFramework_h

    define TestFramework_h

    //这里没有提示,一定手打

    import <TestFramework/TestLog.h>

    endif

    8.暴露Headers供外部项目调用接口.
    选中Target下的Build Phases, 点击左上角"+"号→ "New Headers Phase", 展开Headers, 点击左下角"+", 选择"TestFramework.h"和"TestLog.h"→ 点击add, 将这两个头文件拖动到上方Public下.

    9.然后分别在iOS Device 和 iOS Simulator 下编译.

    在Window→ Projects中左边选择TestFramework工程, 点击右边的Derived Data右边的箭头,打开Finder, 在../Build/Products目录下有真机和模拟器生成的TestFramework.framework

    10.合并Framework.有两种方式

    第一种

    打开终端, 输入:

    cd /Users/用户名/Library/Developer/Xcode/DerivedData/TestFramework-aainjryhnvupalarkmoushxwuwdr/Build/Products, 回车;

    可以输入lipo -info XXX 来查看库的信息, armv7 arm64的是真机, X86_64的是模拟器;
    输入命令:
    lipo -create /Users/用户名/Library/Developer/Xcode/DerivedData/TestFramework-aainjryhnvupalarkmoushxwuwdr/Build/Products/Debug-iphoneos/TestFramework.framework/TestFramework /Users/用户名/Library/Developer/Xcode/DerivedData/TestFramework-aainjryhnvupalarkmoushxwuwdr/Build/Products/Debug-iphonesimulator/TestFramework.framework/TestFramework -output NewTestFramework

    在Products目录下会生成一个NewTestFramework的文件, 将该文件拷贝覆盖TestFramework.framework目录下的TestFramework文件, 新的TestFramework.framework就是真机和模拟器通用的framework.

    第二种

    在Build Phases中添加一个RunScript
    合并可以通过runScript

    if [ "${ACTION}" = "build" ]
    then
    INSTALL_DIR=${SRCROOT}/Products/${PROJECT_NAME}.framework

    DEVICE_DIR=${BUILD_ROOT}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework

    SIMULATOR_DIR=${BUILD_ROOT}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework

    if [ -d "${INSTALL_DIR}" ]
    then
    rm -rf "${INSTALL_DIR}"
    fi

    mkdir -p "${INSTALL_DIR}"

    cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"

    ditto "${DEVICE_DIR}/Headers" "${INSTALL_DIR}/Headers"

    lipo -create "${DEVICE_DIR}/${PROJECT_NAME}" "${SIMULATOR_DIR}/${PROJECT_NAME}" -output "${INSTALL_DIR}/${PROJECT_NAME}"

    open "${DEVICE_DIR}"

    open "${SRCROOT}/Products"
    fi

  • 相关阅读:
    GridView中实现可收缩的面板
    android之xml数据解析(Pull)
    android之xml数据解析(DOM)
    android intent 传递list或者对象
    Android之单元测试
    Directx11教程(48) depth/stencil buffer的作用
    Directx11教程(47) alpha blend(4)雾的实现
    Directx11教程41 纹理映射(11)
    Directx11教程40 纹理映射(10)
    Directx11教程(46) alpha blend(3)
  • 原文地址:https://www.cnblogs.com/shycie/p/5442694.html
Copyright © 2011-2022 走看看