ios - How to read localized image with imageWithContentsOfFile -


this first question here :-)

i have image icon_new.png localized 3 languages. need load in run time using this:

nsstring *path = [[[nsbundle mainbundle] resourcepath] stringbyappendingpathcomponent:@"icon_new.png"]; uiimage *img = [uiimage imagewithcontentsoffile:path]; 

problem above works non-localized images, localized ones, real path appended en.lproj, zh-hans.lproj or other folder names depending on languages included in localization.

now check what's current locale , append path accordingly:

// path work image that's localized - english version of it. nsstring *path = [[[nsbundle mainbundle] resourcepath] stringbyappendingpathcomponent:@"en.lproj/icon_new.png"]; 

however wonder if there's automatic way this? app loads entire ui .xib file proper locale path, specify image name rather it's full path, , proper localized version.

thanks in advance help!

use nsbundle's -pathforresource:oftype:, searches main directory first, , if fails find resource there, checks appropriate localization directories.

nsstring *path = [[nsbundle mainbundle] pathforresource:@"icon_new" oftype:@"png"]; 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -