Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding iOS @1x, @2x, @3x PER device, how to?

I recently asked a question about why we use the 3 different image types listed above, and got good/detailed responses. It also lead me to question something else...

Assume I am working in XCode (with SWIFT) and have the three image sizes @1x, @2x, @3x for a particular say UIImage on an iPhone. Now, I want it to look nice on iPad, so I add some scaling. However, this will change the sizes of the 1x, 2x, 3x images I need for the iPad, so I need to make 3 more to compensate for that new size. Now how will XCode differentiate between the two? Do I need to check what size screen I am using and then choose the images?

I read that assets could help me, but that only deals with iPhone vs. iPad, what if I scale my images across iPhone 4, 5, 6 and iPad. That's a lot of different sizes and @x images, and I read Apple doesn't like device checking so I'm not sure how that would happen.

I hope this makes sense. I get the @1x, 2x, 3x per device, but if my app is being designed for universal device use, then how do I manage all of these different sizes in code for the proper device?

like image 872
CodeMark22 Avatar asked Nov 22 '22 06:11

CodeMark22


1 Answers

You really should use image asset catalog. It makes it almost too easy. Here is the definition Apple gives so you know it's not hearsay:

Image sets: Used for most types of images, an image set contains all the versions, or representations, of an image that are necessary to support various devices and scale factors.

And it goes on further:

Each set in an asset catalog has a name. You can use that name to programmatically load any individual image contained in the set. To load an image, call the platform specific class method, passing in the name of the set that contains the image. The OS will load the image from the set that is most appropriate for the current scale factor

So there really is not much for you to do. I don't know where you heard the opposite

See Documentation here

like image 96
soulshined Avatar answered Nov 23 '22 22:11

soulshined