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