iOS- Including different image sizes for different display sizes - ios

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.

Related

Detecting same image?

currently working on a side project, but I'm stuck on one big part.
The goal is that the user can take a screenshot from a different popular app that contains 6 images/icons. I want it so when the user goes into my app they can upload that screenshot and I can detect the 6 images and place them into a collection view.
The issue is detecting the type of 6 images in the screen shot, I thought about using an OCR like Tesseract but I'm not sure if that would work because there's zero text in the screenshot, only the 6 images. Something that might help is that in that app there all only 50 kind of images. Would create some sort of database of images help? But how would I compare them?
I apologise if this doesn't make sense I just don't know how to word it. Any help would be great.
Assuming you want to be able to do this across multiple types of devices, a computer vision library like OpenCV might be the way to go.
If your users always run the app on the same device (always on an iPhone 5, say) then the icons might always land in exactly the same spot, and you could simply slice the screenshot up, extract the component images, and do a byte-wise compare on the sub-images. However, you've got iPhone 4, iPhone 5, iPhone 6, 6+ screen-sizes, iPad, iPad retina, iPad pro (small and large) to deal with, and possibly portrait and landscape orientations. Presumably the 6 images will land at different spots on the screens of all those different devices, and you'll have different image resolutions to deal with as well. With OpenCV you should be able to find the bounding rects for the images by "looking at" the screen-shots rather than building a complex set of rules.
Take a look at the OpenCV example code for matching SIFT features (the python version here, but you can find examples in other languages as well). It demonstrates a simpler version of what you want to do.

How To Prepare Image Assets in iOS supporting both iPads and iPhones?

I usually do not care much about my assets even if I support the iPads in my project. As long as the imageView for the background of the app is set to Aspect Fill.
Also, here are some links I've found, but not so related to this question.
OLD Question and old answers: How to support both iPad and iPhone retina graphics in universal apps
Cool question and cool answers, however, question and answers focus merely in iPhones:
iOS: Preparing background images for applications
Going back to the question, if I have an Adobe XD file or Sketch, or Photoshop or whatever file that lets me export an image/asset, in what resolution should I start? Do I start with the largest possible size (for iPad Pro) which is 1024x1366 then let the software cut the sizes into #1x and #2x?
If I'm only to support the iPhones, then this would be way lots easier. Thank you!
If your source is vector based, then (obviously?) it's a non-issue...
With bitmap / raster images, you almost always get better results by scaling down.
Depending on the image itself (a photo tends to scale much better than a line-drawing), you may not be happy with simple "auto-gen" features... in which case, you'd need to manually "scale and tweak".
(Hope that helps).

How to include full screen image in an iOS App

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.

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.

Photo Size and Resolution for iOS app

I am working on an iOS application that will show photos either in full screen or in frames in various sizes - like product catalog.
I know I am supposed to use images.xcassets to make things simple and I know I am supposed to create more than one version of the same photo in different sizes.
All I can find is AppIcon and LaunchImage guidelines. What would be the rules I should follow preparing photos to show in different devices? Sizes, resolutions?
Sample: I have 2048 x 1536 raw sized photo (even bigger ones). When it comes to prepare it for iOS app (will work both in iPad and iPhone), what are the dimensions to export my photos from PhotoShop? What would be the biggest sized version?
Could someone please show me a starting point to understand this?
Thanks in advance.
This design guidelines guide is very good. You will find everything you have to know about sizes.
But the simplest way is to use a tool like Asset Catalog Creator to generate your assets. Just drop your original image in it, select your #1x size, and it will generate the catalog for you, for all sizes.
Here is a screen size reference for iPhone devices you may find helpful. Here's one for iPads.
Additionally, if you've got a lot of files you need to resize that you've already exported, you might consider using ImageMagick for batch resizing.

Resources