码迷,mamicode.com
首页 > 其他好文 > 详细

NSBundle 的使用

时间:2014-12-30 18:55:34      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

NSBundle 读取图片 plist text

 

    NSBundle *mainbundle=[NSBundle mainBundle];
    //使mainBundle 对象获取图片的路径
    NSString *imagePath=[mainbundle pathForResource:@"coffe" ofType:@"png"];
    //使用mainBundle 对象获取到 plist 文件的路径
    NSString *plistPath=[mainbundle pathForResource:@"testplist" ofType:@"plist"];
    //使用mainbundle 对象获取到 TXT 文件路径;
    NSString *txtPath=[mainbundle pathForResource:@"testText" ofType:@"txt"];

 处理上面路径;

//处理以上路径的资源
    //imagePath
    UIImage *image=[[UIImage alloc] initWithContentsOfFile:imagePath];
    //plistPath 将plist 文件的内容读到字典中去;
    NSMutableDictionary *data=[[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
    NSLog(@"%@",data);

    //textpath 将text 文件内容输出到字符串中
    NSString *txtcontents=[[NSString alloc] initWithContentsOfFile:txtPath encoding:NSUTF8StringEncoding error:nil];

 

 

通过路径获取到APP的信息如 版本号 ;

    NSDictionary *dicAppInfo=[[NSBundle mainBundle] infoDictionary];
    NSString *AppName=[dicAppInfo objectForKey:@"CFBundleDisplayName"];
    NSString *AppVersion=[dicAppInfo objectForKey:@"CFBundleShortVersionString"];
    NSString *AppBuild=[dicAppInfo objectForKey:@"CFBundleVersion"];
    
    NSLog(@"APP应用的名称:%@",AppName);
     NSLog(@"APP应用的版本号为:%@",AppVersion);
     NSLog(@"APP应用的build版本号为:%@",AppBuild);

 

NSBundle 的使用

标签:

原文地址:http://www.cnblogs.com/xieyier/p/4194219.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!