XCode中加载资源文件

来源:互联网 发布:淘宝办假身份在哪办 编辑:程序博客网 时间:2024/04/30 17:00

转载地址:点击打开链接

将资源文件夹拖到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) ;

原创粉丝点击