XCode中加载资源文件

将资源文件夹拖到Xcode的Supporting File上,然后如下图设置:

 

获取资源文件:

NSString *resPath= [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@“resourceName”];

if(resPath) ;

self.backgroundIV.image = [UIImage imageWithContentsOfFile:resPath stringByAppendingPathComponent:@"A.jpg"]  ;

 

如果资源文件比较大时,建议使用外部路径,模拟器貌似没有沙盒,模拟器里是可以读取指定路径的文件的,当发布程序时,再将路径改为资源文件路径。

如模拟器调试时:NSString* respath = @"/resourceName";

发布时:

NSString *resPath= [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@“resourceName”];

if(resPath) ;

posted @ 2012-06-11 16:03  有容乃大  阅读(8425)  评论(0编辑  收藏  举报