zoukankan      html  css  js  c++  java
  • ios专题 - 使用bundle文件管理资源

    [原创]http://www.cnblogs.com/luoguoqiang1985

    以前,自己写程序,图片等资源放得比较乱。后来,发现有个更好的方法来管理图片等资源文件 --bundle文件。

    1)怎么制作bundle文件

    其实很简单,先新建一个文件,把资源文件放进去,接着,重命名文件为.bundle类型文件。

    真相:

    是不是很简单?哈哈

    2)bundle文件在ios下的使用

    对bundle文件的使用,ios 提供了NSBundle类。

    长话短说,看招~~~~

     1 /*
     2  *  根据枚举获取资源
     3  */
     4 - (NSString *) getResourceByEnum:(nResources) resName{
     5     NSString *result = nil;
     6     NSString *bundlePath = [[NSBundle mainBundle].resourcePath stringByAppendingPathComponent:LGQ_BUNDLE];
     7     NSBundle *bundle = [NSBundle bundleWithPath:bundlePath];
     8     switch (resName) {
     9         case nLuoJunRui:
    10             result = [bundle pathForResource:@"ljr" ofType:@"JPG"];
    11             break;
    12             
    13         default:
    14             break;
    15     }
    16     
    17     return result;
    18 }

    上面这段代码是我的测试代码,里面有几个关键点:

    1)生成NSBundle实例

    [NSBundle mainBundle] - 获得当前可执行APP目录的对象

    NSBundle的resourcePath属性,它是一个NSString 类型。它代表完整路径名字。

      resourcePathstringByAppendingPathComponent ,通过附加astring传递给接收方生成一个新的字符串,前面如果有必要通过一个路径分隔符。

    [NSBundle bundleWithPath:bundlePath] 生成一个指定目录的NSBundle对象
  • 相关阅读:
    7.19 repeater的用法:
    7.18 内置对象
    7.17 三级联动 控件及JS简单使用
    7.15 简单控件 以及 复合控件
    7.14 Repeater
    7.14 ASP.NET介绍 基础
    phpcms图文总结(转载)
    phpcms图文总结(转)
    商业php软件的应用
    php前段时间复习
  • 原文地址:https://www.cnblogs.com/luoguoqiang1985/p/3462466.html
Copyright © 2011-2022 走看看