Image Assest for all device - ios

I have a storyboard file with Width Any & height Any AutoLayout.
I have a Imageview with (0,0,0,0) constraint
I want to show one Static Image. My app is supports both Landscape & Portrait mode with all iPhone & iPad.
So, What should be size of Image View? Image should not be starched or compress
Thanks in advance

You already stated the ImageView's constraints are 0/0/0/0, so its size will be adjusted depending on the device. Use View Mode setting in the ImageView's Attributes Inspector if you are not satisfied with how the image is looking on different devices - for a "background" image, which I suppose is your case, the Aspect Fit setting should be the most appropriate.

Related

How to make an image in LaunchScreen.xib fill the background using Xcode

So I'm trying to setup a full screen background with a logo image centered in its middle with an existing LaunchScreen.xib (for a react native project) and I am having trouble with the autoformat.
I see that I can add constraints to my ImageView to maintain aspect ratio but I'm not sure how to make it fill(crop to fit) the view. When I test on device it just stays the same square as the interface builder and doesn't fill the screen. I've been trying to add different constraints to the image but it doesn't seem to affect it.
Also how do I preview it on different devices as shown in the UI. Selecting different devices doesn't seem to change the square canvas view at all.
BTW I don't want to do it as separate assets for every screen size - I'm curious to learn how to build it using the standard xib interface builder using layout rules.
The xib file was shown by a view that inside a UIViewController.
As you set constraints for UIImage in xib file (e.g. in UIView) you should set constraints of UIView inside the UIViewController.
Then now set constraints of root view to the edges, and set Content Mode of imageView to what you want as apple document said:
The scaleAspectFit and scaleAspectFill modes scale the image to fit or fill the space while maintaining the image’s original aspect ratio. The scaleToFill value scales the image without regard to the original aspect ratio, which can cause the image to appear distorted. Other content modes place the image at the appropriate location in the image view’s bounds without scaling it.

Scale up UIImageView (Storyboard Autoresizing)

I have a UIImageView in a Storyboard. The image used is square. The imageView width and height are equivalent. I want to take advantage of Autoresizing in Storyboard, so that on a small device the image is scaled down and on a large device the image is scaled up. When I test on a iPhone 5 the scaling is appropriate. However, when running on a iPad the results are different. The square is stretched, and this makes sense as the dimensions of the screen is different to the dimensions of the iPhone. How can I avoid this issue, is there a process in which I can scale the view as a whole up until the height is the same as the height of an iPad and then centre the view?
Note - The image has the same width and height and the content mode is set to 'Aspect Fit'
Follow this procedure
1) add a view in which all your content will be added so now you going to use 2 views NewView[with Content] and baseView
now time to add constraints to newView Do like this for leading, trailing,bottom and top [adding wr hr component]
Result For iPad
result for iPhone

How to make iOS ImageView full match window?

I am new in iOS , I am an android developer self-learing iOS just for fun.
As you can see from the picture , I want to make my ImageView full-displayed in the window in different inch iPhone.
If you are an android developer, you may know what I mean is how to make ImageView match_parent in both width and height?
You must set the UIImageView Constraints, like this to adjust in the full screen, 0 spacing in all sizes, and click in Add 4 Constraints
After that, you must check in the UIImageView settings the mode to Aspect Fit, so it will keep the aspect ratio of your image.
I Took the image from your print, here is the expected final result.
Pin the image view on all four sides to its superview via constraints with a constant of zero. Now configure the image view's content mode so that it doesn't distort the image, but rather keeps its aspect ratio (there are two ways to do this, and I don't know what one you want, so you will have to experiment).

UIImageView sizing in AutoLayout + Size classes for all devices

I'm working on app and will for 1st time use auto layout/size classes. Today my first day learning it and I understand constraints now and how to place the images where I want them to be on every devices from iPhone 4s to iPad PRO.
As my main storyboard in Attributes inspector i'm using INFERRED size. In show Assistant Editor, Preview, i'm using all device sizes.
In my inferred storyboard i'm using a UIImageView size 170 Width, 230 Height. Then I use AutoLayout to make it center of every device screen in preview.
Now the issue is this UIImageView covers HALF of the size of iPhone 4s preview but only about 1/5th the size of iPad PRO. How do I alter the size of each UIImageView to the size that I want them to be in each device without changing that centered position of each UIImageView in the preview devices?
You need to first set up your constraints properly and then choose the type of scaling you want.
Set up your constraints:
Click on the Pin icon |-[]-| at the bottom of the screen. Turn on all four orange I-beams. Set the four constants to zero.
Uncheck the Constrain to margins checkbox and click 'add 4 constraints'
Then set your scaling:
Click on the Image View you added to your View Controller.
In the Attributes Inspector on the right, choose your image.
Set the Mode of the View to Aspect Fill (fill entire screen cropping top/bottom or left/right as necessary) or Aspect Fit (letter box image so that entire image is shown uncrossed).
That should work
Maybe you can use a pending or proportion constraints instead of width and height constraints.

Resize image background iOS

Hi I have developed an app for ios 7 and the 3.5 display , actually i am applying all the auto layout constraints needed for the 4 inch display but for me it´s not clear if once i apply auto layout the background image will resize to fit the 4 inch display or if i need to have a new background image to fit in the 4 inch display.
From memory, I believe it would stretch/shrink the image if you used the same image and allowed to automatically resize. I think that the best course would be to have two images and set the proper image programmatically, deepening on UIDevice's idiom property.
If you don't care if the top and bottom edges get cut off on the smaller screen, you could simply make the UIImageView the size of a 4-inch screen, delete any constraints, and center the view. Good luck!
You should use the image compatible with the 4-inch display and set the ImageView contentMode property to UIViewContentModeScaleAspectFit in the storyboard or in your code. So no matter what the screen size is, it will automatically be adjusted and the image will not even get pixelated.
That depends on .contentMode property. The default value of this property is UIViewContentModeScaleToFill. In this mode your image will be stretched to fill UIImageView's bounds. But you might be interested in UIViewContentModeScaleAspectFit or
UIViewContentModeScaleAspectFill in order to preserve aspect ratio.

Resources