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.
Related
I have some views in my app which need to keep always the same aspect ration.
For example I have one view which should always have the width = 2 * height but when I resizing for Ipad the width increase too much and the aspect ration is lost.
It is a way to do that with auto-resizing? Or I should calculate manually for every screen?
Thanks in advance!
EDIT!
This is a screenshot with my view controller.
There are some images. The hover for last 3 items is an UIView with background color. Images are Aspect to Fit content mode. When the Ipad autoresizing the views, images are keep the aspect fit of Image but the view used for hover is not.
Something like this happened:
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).
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.
I'm simply trying to fill the entire width of an iPhone screen with a login button for my users that is basically an image set as the background of a UIButton. This is the result I end up with (Notice it fills width as intended, but shrunken down in height):
My thought process was to make 3 images to compensate for #1x #2x #3x resolutions with different image sizes?
#1x: 144x33px
#2x: 288x65
#3x: 432x97
Now from there I thought I could just fill the width of my ViewController with the UIButton in Storyboard and set the background image of the UIButton which I would think would use the proper one automatically depending on device considering I put them in the right spots in Images.xcassets. I also set the trailing and leading constraints as well as bottom constraint to keep it filling left to right and stick to bottom. I just don't get how I would fix the height issue if it's looking fine in the actual XCode storyboard, but not in the preview or simulator as seen in above photo.
Any help would be tremendously appreciated.
The different image sizes are not used to replace each other when you scale an image. They are used to look nice when there are more actual pixels than software pixels.
For your purposes, you probably want to scale the image with the stretching rules or cap insets.
Check out this answer for an example:
https://stackoverflow.com/a/13367861/1864591
I have a view in IB which contains an image. When viewed in portrait mode the image is fairly large and if the device flips to portrait the image need shrinking to fit the narrower screen height.
Is it possible in IB to specify two sizes for image, one for landscape and one for portrait?
You can use IB to automatically adjust image views to be relative to its surrounding views which if you can make work is a good solution but if you need exact pixel sizes you will probably need to do that in code.