草庐IT

NSbundle

全部标签

objective-c - 使用 [NSBundle mainBundle] pathForResource : ofType:inDirectory: 访问文件

我在名为TextFiles的文件夹中添加了一个文件paylines.txt,该文件夹位于Xcode中我的iOS项目的Resources文件夹中。这是我用来访问文件的代码:NSString*filePath=[[NSBundlemainBundle]pathForResource:@"paylines"ofType:@"txt"inDirectory:@"TextFiles"];NSLog(@"\n\nthestring%@",filePath);代码打印:2011-06-0714:47:16.251slots2[708:207]thestring(null)

iOS开发之0行代码加载NSBundle中的@2x与@3x图片

  本文只针对通过NSBundle对象的方法 pathForResource 获取本地图片资源遇到的图片名无法自动识别@2x与@3x名称的问题进行测试、总结与分享。    加载本地图片资源的方式一般通过以下两种方法:第1种:    UIImage *img = [UIImage imageNamed:@"imageName"];第2种:    UIImage *img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"imageName" ofType:@"imageType"]];注:其他方

iOS开发之0行代码加载NSBundle中的@2x与@3x图片

  本文只针对通过NSBundle对象的方法 pathForResource 获取本地图片资源遇到的图片名无法自动识别@2x与@3x名称的问题进行测试、总结与分享。    加载本地图片资源的方式一般通过以下两种方法:第1种:    UIImage *img = [UIImage imageNamed:@"imageName"];第2种:    UIImage *img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"imageName" ofType:@"imageType"]];注:其他方