How to localize images in xcassets folder in Xcode [duplicate] - ios

This question already has answers here:
How to localize the images in Images.xcassets?
(6 answers)
Closed 7 years ago.
I have two targets in XCode. These are two products based on the same code base but some graphics are different. It's like white labeling. The images are stored in an xcassets folder. How do I localize this? Either localizing for a language or localizing per target is fine with me as the white labeling is per language actually.
I have checked in xcassets but I don't see an option to localize any image.
update: i think one way i could accomplish this is to create a new xcassets folder for my target so it might be called images-mytarget.xcassets. then in the target build phase i could alter the xcassets folder in the 'copy bundle resources' area to use my targets xcassets. I was able to do this successfully. This differentiates xcassets per target. resolved.

While there's (apparently) not currently a way to explicitly localize the xcassets file directly, you could localize the name of the asset to pull using your Localizable.strings file. For instance, say you have a graphic logo treatment for the main menu of a game that needs to be localized. You could put the localized logo treatments in the assets file with different names, add the names to your Localizable.strings file, and then fetch the appropriate image with code like this:
UIImage *img = [UIImage imageNamed:NSLocalizedString(#"MAIN_MENU_IMAGE", nil)];

Related

Image suggestions are not working Xcode 10

I am trying to set image to UIImageView. Its working well in older version.
In Xcode 9.4.1
But in Xcode 10
When I am trying to type name of image, image suggestion is not showing.
Even "Image Literal" is not working. Double clicking on above icon also not working.
Is there any setting in Xcode preferences?
How to enable image suggestion like before?
In Xcode 10 and Swift 4.2, only the code completion function (or auto-complete) of the Xcode IDE has been discontinued for the old way. Here is the new way:
Just type image literal and it will complete with default icon.
Double click on this icon and it will open the media library right side of it.
Just choose your image and it work like before!
Hope I am able to help you!
https://download.developer.apple.com/Developer_Tools/Xcode_10_beta_3/Release_Notes_for_Xcode_10_beta_3.pdf
Code Completion for Swift image literals has been removed in Xcode 10. (38087260)
There seem to be some real issues with how Xcode 10 handles image literals, especially when the name you provide your assets doesn't align with the filename of those assets.
The following are the steps I've found will restore image literal previews.
Add an image via the media library picker.
If you have multiple resolutions for your image (e.g. #1x, #2x, #3x), Xcode will inconveniently drop them all into your code and throw an error to let you know you've done something naughty.
Delete two of the faulty image previews, if necessary. You may be left with a default image icon instead of a preview of your actual image.
Comment out the lines on which you're setting the image. You'll see the image literal references the filename of your asset rather than the name you've provided in the asset catalog.
If you've renamed your assets after adding them to your asset catalog, this seems to sometimes prevent Xcode from reading the asset appropriately.
Change the filenames to the appropriate asset names.
You can find the asset names in your asset catalog.
Uncomment the code and, if the default image icon is still visible, double click on the image icon. It should then display a preview of your actual asset.
You may also need to clean and rebuild your project.
use command + shift + M to popup the Media Library then Simply Drag and Drop into your Code
OR

Images living inside an imported pod .xcasset are selectable (and viewable) inside Interface Builder storyboard, but won't show in the simulator

I'm in the middle of some "Proof of Concept" project regarding Cocoapods, .xcassets, Swift 3, "cross-project loading images" (from pod bundles onto the main storyboard), etc...
My main problem right now is "images living inside an imported .xcasset (via pod install/update) are selectable and appear inside Interface Builder main project storyboard, but won't show in the simulator".
In runtime, the simulator running my main app yields something like this:
Could not load the "cx_green_tick" image referenced from a nib in the bundle with identifier "MyCompany.ios-appbase" when it tries to render the selected image. And then nothing appears on the expected placeholder space, just empty space.
MyCompany.ios-appbase is the bundle name of my main app.
cx_green_tick is the logical name of some image resource happily living inside my "Commons" imported project Media.xcasset folder.
This image resource consists of 3 proper .png files with their #1x, #2x, #3x names, etc...
My Commons Pod Project (the one containing the .xcasset files/folders I want to use in my main project) has a .podspec file with the following resources definition (among many other things):
s.resources = [ 'Commons/**/*.{png,jpeg,jpg,storyboard,xib,ttf,otf}' , 'Commons/**/*.{xcassets, imageset, json}' ]
Once I'm in the root folder of my main project, I just type "pod update/install" and I can see how the different pods I defined in my main app Podfile start to download and get perfectly stored into the expected Pods folder of my main project.
Then, inside Xcode, I can see how inside the Pods/Commons/Media.xcassets container there's the expected cx_green_tick image resource, with its 3 proper resolutions.
Then I change onto my main app Main.storyboard and select the cx_green_tick image resource to be used onto a UIImageView placeholder. Whenever I do it, I can see how this green tick image appears inside IB. But if I run the simulator, this image doesn't appear on its placeholder.
I'm using Swift 3.0, XCode 8, deployment target is iOS 9. All my involved Podfiles have the use_frameworks! keyword/line active.
I've REALLY been googling this for many hours (yesterday and today) but I can't see any hint on how to do it without having to do the image load by hand, programmatically. (In case it's something achievable, which I'm not really sure after all this)
BTW: If I load this image programmatically, explicitly selecting the bundle where the image resource lives inside Media.xcassets, the image appears without any problem in the simulator.
That could be a partial solution, but our main goal was not having to perform image loading by hand. Specially when (apparently) IB shows this image onto its image_name resources combo list on the top part of the screen for the UIImageView placeholder.
Any hint?
(If something is unclear, please ask and I'll try to reword it somehow )
Greetings and thanks in advance.

What's really happens when I create a "New Sprite Image" inside my Xcode images.xcassets?

Days ago I asked for How check the .spriteatlas sizes generated by Xcode? but I got no answer so I decided to slightly change my question:
What happens when I choose this option here inside the images.xcassets section?
Does Xcode provide a full atlas manager and I just have to add single images inside this folder or should I put inside a whole atlas (created by my self with the .plist file attached)?

How to Localize Image Files in IOS project

i went through few video tutorials and links for localizing an IOS app,there are few very good tutorials about the localization though, i am facing issues with localizing the resources. i am using assets catalog for management of the resources in the app and i am using launcher.xib for my custom spalsh screen which contains a lable and an imageview. i will be setting the image to imageview based on the language settings (english and french). i followed initial steps for adding localization feature to the app, and it created fr.lproj directory in my xcode project folder. i copied few images with french text in to fr.lproj folder and few english texted images in to base.lproj. in assets catalog i used english texted images default images for the imageview, now i run the app by changing the language setting of the device, and result is in english. i went through this link http://www.raywenderlich.com/64401/internationalization-tutorial-for-ios-2014 where author says we cant localize the assets catalog, and he is doing a little trick to do it. but my problem is launcher.xib doesnt linked with .h and .m files and dont have any methods where i cant set an image programatically. How can i achieve this? help Me please..
Thanks.
[UIImage imageNamed:#"NSLocalizedString (#"image_name_key", nil)"]
image_name_key will contain your image name in different language in string files. like
image_name_key = #"fr.jpg"
image_name_key = #"en.jpg"

xcode 6 iOS launchScreen.xib localization issue

In my app I have three languages. The launchScreen.xib has three localzations too.
Like the localizable.strings I changed the text that should be used by the Object-ID.
When launching the App there is always the english text used, not the localized. And there is a "X" int he symbol of the LaunchScreen.xib and LaunchScreen.xib (Base). Why? How can I solve that issue?
The correct answer to specifically localizing the launch screen is here:
Localization of Default.png is not working
And for shortcutting I'll paste the main steps:
Create InfoPlist.strings file. (File,New,Resource,Strings)
Localize it and add the key "UILaunchStoryboardName" with the value being the name of the xib you want to be shown as the launchscreen for that localisation.
For e.g. for the Spanish version, add your launch screen key and name for the Spanish version of your Launch screen in the newly created InfoPlist.strings localized for spanish.
"UILaunchStoryboardName" = "Launch_es";
As Apple's document, launchscreen will never locale your text:
"Avoid including text on your launch screen. Because launch screens
are static, any displayed text won’t be localized."
https://developer.apple.com/ios/human-interface-guidelines/graphics/launch-screen/
I would like to give clear description of fix according to previous info.
I got the same issue and couldn't find clear description. I have Xcode 8.2.1 and Swift 3.0 now.
Finally:
I copied LaunchScreen.storyboard and added it to project with name Launch_ru.storyboard. After I did localization of Launch_ru.storyboard.
Next need to choose it and add Base Localization.
Next need to add to added during main localization file InfoPList.string key "UILaunchStoryboardName" = "Launch_ru";
where Launch_ru is name of my new Launch_ru.storyboard.
These three actions fixed my issue.
Fawkes' answer is the right one:
Create InfoPlist.strings file. (File,New,Resource,Strings)
Localize it and add the key "UILaunchStoryboardName" with the value being the name of the xib you want to be shown as the launchscreen for that localisation.
One thing to note is that, all the launch screen storyboards that you'll end up having need to be barked as "Base localization" in the Files Inspector:
If you accidentally mark them as a localization for a different language, it will not work (it will just display a black screen!)
I had same issue, after that i used MCLocalization it is very easy to integrate in your app. It worked perfectly for me

Resources