How can I get relative path?
I'm programming on objective-c. I have 3 folders with 3 languages such as en, ru, fr with pictures 1.png, 2.png, 3.png. How can I get relative path for my pictures? How should I add this files in my project? I have some warnings. Its 开发者_StackOverflow中文版because I have the same name of sources.
Warning: Multiple build commands for output file /Users/Kate/Documents/XCode_progs/MyProject/build/Debug-iphonesimulator/MyProject/1.png
Warning: Multiple build commands for output file /Users/Kate/Documents/XCode_progs/MyProject/build/Debug-iphonesimulator/MyProject/2.png
Warning: Multiple build commands for output file /Users/Kate/Documents/XCode_progs/MyProject/build/Debug-iphonesimulator/MyProject/3.png
My code doesn't work:
CCSprite *button = [CCSprite spriteWithFile:[NSString stringWithFormat:@"%@/1.png", lang]];
Add your images to your project, that you can call:
[[NSBundle mainBundle] pathForResource:@"1" ofType:@"png"];
If you add localization to this resource (png image) (in XCode 4 choose image file and in Utility panel (on right hand) you can add different localizations), then in runtime iOS choose properly localized file automatically.
精彩评论