Image asset size in Xcode interface builder - ios

If I add an image view onto interface builder in Xcode and it has a size of 200 x 100 (size in Xcode), how do I know what size to make the image asset for 1x 2x and 3x.
If I make it 600x300 pixels in photoshop for the 3x and then try to use this image it doesn't look very clear on an iPhone 7 plus so how do I know what resolution the image assets should be for a given image view size

If I add an image view onto interface builder in Xcode and it has a size of 200 x 100 (size in Xcode), how do I know what size to make the image asset for 1x 2x and 3x.
Resolution is a matter of the correspondence between points and pixels. If the desired image size is 200x100 points, then you would provide these three image sizes:
1x: 200x100 pixels
2x: 400x200 pixels
3x: 600x300 pixels
If we are running on, say, a 2x-resolution device, the image will be loaded with its scale set to 2, so that 2 pixels will correspond to 1 point.
Note that you should not attempt to make the 3x image by simply upscaling the 1x image. That will obviously look terrible. You should start with a 600x300 original and downscale to get the 2x and 1x images.

Related

How to decide 1x size for image?

I have one ImageView but the width and height are not constant. Both will change as per device width and height. (Height of ImageView is 1/3 of screen size and width is complete device width)
Example:
Proper Colors
Height
Width
iPhone SE
375
222.5
iPhone 11 Pro Max
414
298.67
iPhone 12 Pro Max
428
308.67
iPhone 12
390
281.33
As we see, width and height are varying so in this scenario what should be size for 1x image. Once we get 1x size then 2x and 3x sizes we can find easily.
Note: If width and height is fixed then I know how to find 1x, 2x and 3x.
Example: If imageView is 20x20 then, 1x = 20x20, 2x = 40x40, 3x = 60x60, But in above scenario width and height is not constant.
Note: If width and height is fixed then I know how to find 1x, 2x and 3x. Example: If imageView is 20x20 then, 1x = 20x20,2x = 40x40,3x = 60x60
#1x, #2x, #3x has more to do with the pixel density of the screen and not the size of the image. If the same sized image is displayed on a higher resolution screen then iOS will automatically choose a #3x version of the asset. Think of video quality on YouTube, a 720p and 1080p has the same size. But the 1080p video is more clear.
But in above scenario width and height is not constant.
As to dealing with the changing size of the screen, you need to decide before hand how your images should be displayed. This is a UI designing concern. UIImageView has various ContentMode options that you can use. For example,
scaleAspectFit: The option to scale the content to fit the size of the view by maintaining the aspect ratio. Any remaining area of the view’s bounds is transparent.
So if you use scaleAspectFit then on larger screen sizes you will have more blank space to the sides of the image.
Also, please take a look at Apple's Human Interface Guidelines for Image Size and Resolution and 1x, 2x and 3x Image Scaling on iOS Explained blog post.
The coordinate system iOS uses to place content onscreen is based on measurements in points, which map to pixels in the display. A standard-resolution display has a 1:1 pixel density (or #1x), where one pixel is equal to one point. High-resolution displays have a higher pixel density, offering a scale factor of 2.0 or 3.0 (referred to as #2x and #3x). As a result, high-resolution displays demand images with more pixels.
When you can fit more pixels on the same screen real-estate, you also need higher resolution images. This is where 1x, 2x and 3x come in. You provide higher resolution image files for the same assets, which are automatically selected by iOS when your app runs on a high-PPI iPhone model.

What happens if iOS images sizes are not rightly calculated?

What happens if I will have an 1x image at 100x100, the 2x image at 190x190 and the 3x image at 290x290? Will it make any difference?
I used Slender to analyse the images in my project and it flooded me with several warnings saying the image sizes are not right and the dimensions are a mismatch.
5 or 10 pixels doesn't make major difference when image size is 200 or 300 pixel. But, you should follow the standard(as per apple guideline) that 2x should be double and 3x should be triple of 1x respectively.

Wrong image being loaded by UIIMageView

I have this iPhone app targeted to iOS 7.
I have created an entry on .xcassets called mainImage that is device specific for iPhones. So xcode presents me with 4 slots I have to fill with images. that has these images: 1x, 2x, Retina 4 2x and 3x.
I have filled each slot with the following images in order:
1x = 320 x 480 pixels image
2x = 750 x 1334 pixels image
Retina 4 2x = 640 x 960 pixels image
3x = 1242 x 2208 pixels image
Then I have a viewController on storyboard that is adjusted with the iPhone 6 size and the imageView there is adjusted to load just "mainImage".
The image shown there is the iPhone 4 2x stretched, not the correct one. It should be showing the 750x1334 image.
If the imageView is adjusted with "mainImage", wasn't it supposed to load the correct image for the viewController size?
I run that on iPhone 6 and indeed the image shown is the iPhone 4 image stretched.
Anyway to fix that?
It does not work like that. You can have separate images for different screen densities, not for different screen sizes. You have to add a separate entry for each screen size and select the image yourself. Launch image is the only asset that works automatically with different screen sizes.
How to specify size for iPhone 6/7 customised edge-to-edge image?
Follow this guidelines for each iDevice:
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/IconMatrix.html#//apple_ref/doc/uid/TP40006556-CH27-SW1
In fact there is one more limitation/bug on xcassets, beyond the impossibility to localize it to different languages, that is the ability to load a different image or better the correct to iPhone 6. Apple did not realized that the way xcassets work now will not load the correct image if you care using full screen images.
The solution for that is not to use xcassets, create the images you need and a class to call the correct image based on the screen size/needs.

Image size optimizing for newer retina screens

I need to implement some photo uploading function, but I'm a little bit confused because of the pixel/size dimension of the images. I need to display a square cropped image which size in IB is 320 x 320.
I've made a little research, but couldn't find an exact answer. I've checked Instagram, and it uses 640 x 640 pixel images everywhere. How is that possible? The iPhone 6 Plus's screen resolution is bigger then the Full Hd, the width of the screen is 1136 px while an Instagram image is 640 px wide (and doesn't pixelated) . I don't think that they save images for every devices separately.
So UIImageView can display non-retina images on retina screens like this? Or what's the reason why the 640 px is enough?
UIImageView can scale the image you pass to it. So if you were to pass a 640x640 pixel image into a UIImageView that was displayed larger on screen, it would be scaled to fit appropriately. It would scale up and you would lose quality when displayed that way.
As for the IB size being 320x320 points, that doesn't directly translate to pixels. Older devices worked that way, but newer (retina) devices scaled at 2x (including the iPhone 6). So a 320x320 pt UIImageView in IB would actually render at 640x640 pixels. The 6 Plus renders at 3x, so 960x960 pixels.
I'm not sure how you concluded that Instagram was using 640x640 on all devices, but if that is the case, the 6 Plus is scaling images to 960x960 pixels and losing quality. It's possible that the loss isn't noticeable in most cases, but I would guess they request larger images for the larger screen.
http://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions

Confusion on what pixel size to set in new image set

In Images.xcassets under New Image Set i'm going to use device specific to get the same image for different sizes. I'll be using iPhone 2x, Retina 4 2x, 3x and iPad 1x, 2x. If for iPhone 6+ I want to make an image 40x40 Pixels #3x and for iPhone 6 I want to make the image 30x30 pixels #2x, am I not allowed to do that, is the image supposed to be only 20x20 for 2x? Can I just put both images for example 50x50 one in 2x and other in 3x or is this not allowed?
Your images have to be exactly the right size, you can't give it any other size.
So 30x30#2x must be a 60px by 60px png file, and 40x40#3x must be 120px by 120px. You multiply the width/height by 2x, and the same for 3x.

Resources