Is it obliged to use Assets.xcassets? - ios

I would like to know if we were to put our images in the xcode Assets.xcasset or an image file could be enough?
Thank you

https://developer.apple.com/videos/play/wwdc2018/219/
From WWDC 2018:
"...for artwork that comes with your application, we strongly encourage you to use image assets. And there are a number of reasons why."
Some of those reasons:
"Image assets are optimized for name based and trait-based lookup. It's faster to look up an image asset in the asset catalog, than it is to search for files on disk that have a certain naming scheme."
"managing buffer sizes"
"...per device thinning, which mean that your application only downloads image resources that are relevant to the device that it's going to run on and vector artwork."
Vector artwork optimization: "...if your image gets rendered in an image view that is larger or smaller than the native size of the image it doesn't get blurry. The image is, actually, re-rasterized from the vector artwork... The asset catalog compiler has, actually, already produced a pre-rasterized version of that image and stored it in the asset catalog. So, rather than doing the complicated math of rasterizing your vector artwork into a bitmap, we can just decode that image that's stored in the asset catalog and render it directly into the frame buffer."
This is not an exhaustive list, click the link for more. So to answer the question, using the asset catalog is certainly not required, but it would be foolish not to use it for artwork that is delivered with the application for the reasons mentioned.

No. It is not required to use .xcassets files. You can also just add images and other resources to your Xcode project.
However I would always use Asset Catalogs if possible, because it gives you powerful features, such as using different images for different devices/gamuts/etc.

Related

Can you create an UIImage from PDF data?

I am loading a remote PDF file and trying to turn it into an UIImage (for showing in an UIImageView), and am surprised that it doesn't seem to work. Even though local PDF files in the Asset Catalog work just fine, is PDF not supported outside of that?
Edit: I found https://developer.apple.com/library/archive/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/LoadingImages/LoadingImages.html which suggests that nope, PDF doesn't work. So that leaves me with the question: why/how does it work for local files in the Asset Catalog? Why or how is that different?
To answer your "Why or how is that different?" question...
When you add a PDF file to asset catalog, Xcode renders #1x, #2x and #3x versions at build-time.
You can select Preserve Vector Data to have the pdf "rendered on-the-fly." This generally works well, although if you have a lot of pdfs and you're doing a lot of manipulation with them, it may reduce performance.

PDF image for iOS Assets

we can add image as pdf in ios assets for application.But i'm confusing that which approach is good for application.
Png file direct drag and drop to Assets
or use image as PDF
i have follows links
https://icons8.com/articles/how-to-use-vectors-in-xcode-7/
and https://bjango.com/articles/idontusepdfs/
but not able to decide which one is better solution for assets.
i know how to works with pdf asset but cannot decide which method is better from development point of view.
Thanks in advance.
If your artwork has complex gradients, generate the PNGs yourself. Otherwise, use PDFs. That's how I read it.
Personally, I have the luxury of working with a designer who just gives me assets at all the required sizes. On another project, Sketch was used which can auto-generate PNGs from a script as part of the build process. So I've never actually used PDFs.

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

Adding image sets to images.xcassets catalog programmatically in 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).

How can I recover PNG images from a .pvr.ccz file?

I have an existing Cocos2D game that uses sprite images taken from a .pvr.ccz file, probably generated by TexturePacker. However, I don't have the original PNG images used to create that file, and I need to make some changes to the images in the game. Are there any tools or techniques that I can use to pull the images out of the .pvr.ccz file, or do I need to write my own tool?
Not possible if they use the encryption option of Texture Packer:
I've added a new feature to TexturePacker which helps you to prevent all this from happening. It's called ContentProtection and simply encrypts the images.
Your app will still be able to decrypt the data, but somebody else is going to have a hard time getting it done.
Source: https://www.codeandweb.com/texturepacker/contentprotection

Resources