How to include full screen image in an iOS App - ios

I want to add a full screen image into an iOS app and I want to know the best way to support different devices
The problem with using the image assets: 1x, 2x, and 3x is that 2x is used for iPhone4s, iPhone5, and iPhone6 which every one of them has a different dimensions
Should I use a different images (one for every device) and include them as resources then at runtime I choose the image based on the current device? I feel like it is not a good solution
any suggestions of a more elegant way?

If you click on the asset you can configure more options and sizes depending on various parameters. Conceptually similar to what happens when you create a new LaunchScreen Item in the asset. See image.
Depending on what is the wanted end results you can also adopt different tactiques, like having a background image that is big enough to be set as "Center" aspect mode and the eventually place other images like logos or titles on top of it. Or again just have one big image that can be set as "AspectFit".

It's not a good idea to have a different image for every device. Either use stretching or tiling to handle different sizes, or make an image that you can clip on smaller screen sizes, or you will have to have different images for each device and code to detect which to use and spend time maintaining that whenever new devices are announced.

Related

Should I create multiple background images for various sizes of iPhones?

I am trying to add a full-screen background image for different sizes of iPhones as shown below.
I am thinking two options:
(1) I will make 4 images for each of the screen (640x960, 640x1136, 750x1334, 1242x2208)
(2) I will make one image (1242x2208) that has bleeing areas to cover all 4 sizes.
For option (1), since the background image looks the same, is creating 4 images necessary (app size increases)? For option (2), is it a correct way? I have not found anyone talking about this method while researching online.
Which one should I go for? Or better alternative?
As it is a background image, I suggest making a large image. Make it the same ratio as the small iPhones. Then use either ScaleAspectFit or ScaleAspectFit for the 6+. However, do not scale the image up to the 6+. Good luck!

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?
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
You need to check the size of the biggest image, if you are using an iPad figure out the size of the UIImageView frame. For instance if it is 400*400pts then your image will be 1200*1200. Just use a single image. I don't think you need to include the #2x and #1x. The 1200*1200 covers your bases for the largest possible image and scaling down will still have plenty of pixels left over for the full #3x resolution on other devices and so on. This is how I understand it anyway. I also wondered this myself and only found #1x #2x #3x useful for things that I didn't scale up as the screen size increased such as some buttons.

Can we use just one set of image assert for all resolutions in iOS Development

I just want to use one set of image asserts for all iPhones and iPads(Universal), Is it possible to do the same? or what will be the best solution for the making a build lighter.
YES, it is possible ti use one image asserts for all devices. just add new image set
in assert by Right click. And the add images for required devices in created Image set.
you can use Image set but it's name,and images are automatically loaded with different devices.
UPDATED
if you want to titlelogo.png for all device then make new image set in Images.xcassets and name it as AssetTitlelogo. and the add all images in it as in screenshot.
You use image by
[UIImage imageNamed:#"AssetTitlelogo"]; /// use your asset Name
It's load right image for right Device..
Yes, if you use a retina image without the #2x or #3x in the name and your UIImageView is set to ScaleToFill it will automatically scale down your image on non-retina devices. it is easy to test with the simulators to see how the image will look at the different screen resolutions.
the trade off is non retina devices will suffer with more memory usage than is needed for them (and usually the non-retina devices are some what limited in memory already compared to the latest apple products) but if you arent dealing with a lot of images on the screen at once then this shouldnt have an adverse effect

Image looking blurry on non-retina iPad

I know I should have two versions of my image, one standarad and one #2x but my app downloads a vast amount of content which i need to optimise. Im looking at using just retina images in my downloaded content and then seeing if there is an objective c way to take a graphic half it and make it none retina. using a retina image on my non retina ipad looks blurry.
For images. You have to download separate images with your desired dimensions. For example Facebook timeline has separate image for user icon (e.g. 25x25). and For ever post having photo, a thumbnail is generated say it has dimensions (310x160). And then when a user clicks the image to view. It opens the original Image. Whatever dimensions it has. So, In your case. you have to download two images. One for your non retina and one for retina. You can use Flicker API's for that.
Note: You can skip this and continue with retina display because Non retina devices are rarely being used now. So, every one has retina device and app will work perfect with your existing scenario.

iOS- Including different image sizes for different display sizes

I am new to iOS programming and programming in general so this will probably be a fairly easy question to answer for someone who is experienced.
I am making a game using sprite kit and I need to include different background image sizes for the different retina display sizes on the iPhone 4 and 5. I am using a graphics package to create the images in .png format then adding them into the project, the issue I have is that, if I make a 640x1136 size image, it works on the 5, and if I use a 640x960, it works fine on the 4 but leaves blank space around the edge on the 5. (I am running it on the simulator)
If I include two identical images with different names, one for each device, how can I load the right one in? Do I only need high resolution image and can use some code to change how it loads the image in, so that it covers the whole screen without pixelation or loss of quality on both devices?
Any help or advice is appreciated. I apologise if this is a simple question, thanks for your time.
Note:
I found out plenty on the internet about using the #2x suffix for high resolution images, but that's not what I'm looking for. I know how to code for different resolutions, just not two different screen sizes with the same resolution, if that makes any sense.
If you're on iOS 7 SDK which you most likely are, make use of the .xcassets catalogue. It has options for different screen sizes, put the different versions of your image there. And then load image in code.

Resources