Adding image sets to images.xcassets catalog programmatically in iOS? - ios

I've searched high and low on stackoverflow and google for an answer to this question. Perhaps it's not possible, or I may need to devise a different method to do this.
In our iOS app we have a whole bunch of image sets in images.xcassets. But we're moving to a more dynamic environment where we'll be downloading image sets instead.
I'd like to try and stick with the convention of having everything in the images.xcassets folder. Except as said, I want to dynamically create the image sets based on the data we retrieve from our server. Is this possible?

So there is a way to do this, but it's iOS 8.0 and above. Unfortunately, we're supporting 7 and above so I can't use it.
But for anyone else who's interested, you can use the UIImageAsset class to do what you need to do when you want to create a container for your images to encapsulate different resolutions, as the images.xcassets container currently does.
UIImageAsset docs

This answer gives a good overview of the XCAssets folder at runtime: Can I access an xcassets directory on the filesystem? - it looks like it's the wrong way of going about things.
I believe it is recommended that you use the temp or document folders, depending on the how long you wish to keep these images (https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html).

Related

Appcelerator : ImageView and local files

for two days now, i have been looking for the correct place to put my local images and the correct way to access them in the Appcelerator platform (working with Alloy framework).
All i want to do is simply display a local image through an image view component. It works well with an image get from URL but seems impossible to get it from a local file.
this is an simple image view declaration in my index.js controller
/app/controllers/index.js. Where do i have to put my image to get this code working?
var img = Ti.UI.createImageView({
image:'images/DefaultIcon.png',
top:10,
width:100,
height:100
});
$.index.add(img);
I have read all the documentation about that issue and read a lot of similar questions over the internet. Anyway, none of the answers i've been reading bring me the correct solution.
No matter where i put my images into my project directory (assets folder, root folder, resource folder, image folder), those images seem to be not accessible !
I'm currently developing on iOS platform...
I really hope some of you guys have the solution ...!
Best regards,
Quentin
You need to put the images in the /app/assets/iphone/images folder.
Within that folder you can create as many folders as you'd like, the only thing you need to do is update the path accordingly.
So, you have an image with the name myIcon.png. Put this in /app/assets/iphone/images/myIcon.png (and don't forget to include #2x and #3x images in the same folder).
Then, in your imageView use this path /images/myIcon.png.
Want to put it in a folder? For example /app/assets/iphone/images/icons/myIcon.png then reference it in an imageview with /images/icons/myIcon.png.
For android you too need to use the images folder inside app/assets/android. But to specify dimension specific images you can put them in ldpi, mdpi,hdpi,xhdpi,xxhdpi and xxxhdpi folders as specified by Android

Image Localisation using images in Assets

I found the following issue exists for a long time, And I also find there are many solutions available, But this thread is to get recommended way to do it.
Issue:
We cannot able to localise the images directly from assets folder but we can able to localise the images which we place it in File inspector as shown in the image.
I need to know the answers for the following questions:
- Why we don't have localisation for images in Assets folder ?
- What is the Apple recommended way to localise images ?
Please answer the questions. And if you have any link recommended by Apple please add that with your answers.
Note:
- Its not a duplicate question, am asking this since we know we cannot able to extract / reverse engineer to get the images used in the iOS application assets. But thats not the case with the images placed in the file inspector which can be extracted. So this question is all about Apple's recommended way to approach image localisation and not possible solution.
There is not any correct way to localise the xcassets file directly,
but still you can localize the name of the asset to get using your localizable.strings file.
For example:- you want to put any main image at home screen for different different region so you can save that image to xcassets to using their localise name and you can fetch that image like this.
UIImage *img = [UIImage imageNamed:NSLocalizedString(#"Main_image", nil)];
and here is the link from apple that spacify how you can localize the image. LINK

Multiple NFT tracking ARToolkit iOS

I am trying to create an ARToolKit app in iOS with multiple NFTs.
I have generated the featured set(.fset) and image set(.iset) of both the images, edited the markers.dat file as well.
When I try to scan the images, it displays the object only on one image, on the image which is declared first in the markers.dat file. If i change the order of declaration of the images then the object is displayed on only the second image(which was declared first in the markers.dat file).
Is this some kind of bug or am I doing something wrong?
look here:
https://github.com/artoolkit/artoolkit5/issues/115#issuecomment-217771991
There I listed all the steps that you need to check if you want to have multiple NFT working. I did this for an Android example but it should be the same for iOS.
Let me know if it works for you.

Get a list of images in the project in iOS?

I imported a lot of images into my app. I could use imageNamed: for each item but it is very hard to do manually (~50 images). Can I somehow get a list of them? It is just for testing purposes, so private api is acceptable too.
Or will it be easier for me to rename them to something like 1.jpg, 2.jpg and etc.
the best way for you is rename you file to ( 1,2,3 xxx )
but there is a tool that help you to see you picture from app bundle during your coding
KSImageNamed

forge.topbar.setTitleImage(URL,success,error); dynamic image .. fileCache?

I have been told this is possible to do but cannot get this to work.
Basically I am trying to cache and image using forge.file.cacheURL()
Now I can get the file just fine and display it in the page by creating a new Image object but what I want to do is use this cached image to change the image in the topbar.
When ever I try to do it I get an error saying "file not found" and after reading the docs a little more it seems that trigger may have "src/" coded into the class because if I put just "image/logo.png" the logo.png will show up in the header because its part of the app package.
I guess the question is.. Is my assumption correct?
Thanks!
The native UI elements (topbar/tabbar) load images directly from your apps package, not through a URL in the same ways images are shown in the webview.
What this means is that currently you can only use images included in your app in the topbar/tabbar modules.
in case anyone is interested in this, the ability was added a while ago to the API so you can now use a cached image or filesaveURL feature of forge to change the header image dynamically.

Resources