zoukankan      html  css  js  c++  java
  • 【转】 iOS学习之NSBundle介绍和使用

    bundle是一个目录,其中包含了程序会使用到的资源.这些资源包含了如图像,声音,编译好的代码,nib文件(用户也会把bundle称为plug-in).对应bundle,

    cocoa提供了类NSBundle.

    我们现在用bundle获取程序里的一张图片,并显示到View上。

     

    新建一个Single View Application,并在加入viewDidLoad方法里加入如下代码:

     

    [cpp] view plaincopy
     
    1. //    通过使用下面的方法得到程序的main bundle  
    2.     NSBundle *mainBundle = [NSBundle mainBundle];  
    3.       
    4.     NSString *imagePath = [mainBundle pathForResource:@"QQ20120616-1" ofType:@"png"];  
    5.     NSLog(@"%@", imagePath);  
    6.     UIImage *image = [[UIImage alloc]initWithContentsOfFile:imagePath];  
    7.     UIImageView  *imageView = [[UIImageView alloc] initWithImage:image];   
    8.     [self.view addSubview:imageView];  




    在项目上右键,add图片文件图片文件QQ20120616.png。

    运行程序:

    打印出来图片路径如下

     

    /Users/rongfzh/Library/Application Support/iPhone Simulator/5.1/Applications/3B8EC78A-5EEE-4C2F-B0CB-4C3F02B996D2/iOSSandbox.app/QQ20120616-1.png

    我们可以看到,图片在iOSSandbox.app这个包里,

    图片显示:


    图片取出来并显示了。

     

    from:http://blog.csdn.net/totogo2010/article/details/7672271

  • 相关阅读:
    加密
    读取excel
    poj 1852 Ants
    关于运行时间
    poj 1001 Exponentiation
    Poj 3669 Meteor Shower
    一道简单题目的优化过程——抽签问题
    高精度四则运算
    Usaco_Contest_2013_Open_Bovine Problem 1. Bovine Ballet
    h5 音频 视频全屏设置
  • 原文地址:https://www.cnblogs.com/xuan52rock/p/5114135.html
Copyright © 2011-2022 走看看