ios - NSBundle mainBundle pathForResource: Not working unless @2x included -
i have files named: landing_load1@2x ...landing_load4@2x in project. (no non-retina files)
this code works:
for(int x=1; x < 5; x++){ nsstring * imagetitle = [nsstring stringwithformat:@"landing_load%i@2x", x]; uiimage * loadingimage = [uiimage imagewithcontentsoffile:[[nsbundle mainbundle] pathforresource:imagetitle oftype:@"png"]]; [loadingimages addobject:loadingimage]; }
but doesn't work:
for(int x=1; x < 5; x++){ nsstring * imagetitle = [nsstring stringwithformat:@"landing_load%i", x]; uiimage * loadingimage = [uiimage imagewithcontentsoffile:[[nsbundle mainbundle] pathforresource:imagetitle oftype:nil]]; [loadingimages addobject:loadingimage]; }
and doesn't work:
for(int x=1; x < 5; x++){ nsstring * imagetitle = [nsstring stringwithformat:@"landing_load%i", x]; uiimage * loadingimage = [uiimage imagewithcontentsoffile:[[nsbundle mainbundle] pathforresource:imagetitle oftype:nil]]; [loadingimages addobject:loadingimage]; }
question: know don't have explicitly call @2x or specify file type, ideas why it's not working unless explicitly write whole file name out?
note: tested on ipad 4
record
nsstring * imagetitle = [nsstring stringwithformat:@"landing_load%i", x];
means have pair of graphics files resource - both "filename.png" , "filename@2x.png". or, alternatively, can used "alias" "filename.png" if have "filename@2x.png", have 2 possible variants: 1. use that
nsstring * imagetitle = [nsstring stringwithformat:"landing_load%i@2x", x];
or have both of files ("filename.png" , "filename@2x.png") resource.
Comments
Post a Comment