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) ;


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM