Auto-resize views on iPad with same Aspect ration? - ios

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:

Related

Custom specific Tabbar

I have a design for app where Tabbar looks like this:
I tried to add TabBarController and change its background but TabBar's background has only original size of image that looks bad on different iPhone models.
The next idea was to add a View on the bottom MainView and add UIImageView in bottom View. It looks nice but only on iPhone 7/8. On another models it looks bad because they have different width and height.
You can use aspect ratio for handling different device resolution for tabbar view. So it will create tabbar with different height and width for each device as per its size.
You can refer below links for aspect ratio:
Autolayout aspect ratio for UIImageView / UIView

Image Resizing for different screens XCode

I've been trying to find a solution to this problem for a long time but I haven't been able to solve it. How do I make an image appear smaller so it would fit the screen on a smaller device? When I have in on a larger device it fits fine but when switched to a smaller screen the images start to overlap.
Example of images overlapping
I would really appreciate the help. Thank You!
Use auto layout and set your Uiimageview aspect ratio to 1:1
There are a lot of ways. Some are mentioned below:
Using Auto layout
connect every image to side of main view and set their widths and height ratio 1:1 , also set their width proportional to main view widht.
using stackviews and autolayout
1st set images width proportional to main view width
then set their aspect ratio 1 : 1
then add the columns to 2 vertical stack views and add both columns to horizontal stackview.
set the left right and bottom constraint of final stackview
You can use auto resizing as well, but that is not totally reliable.
autoresizing is default behavior of view. In your case you have to set flexible width and height of each image

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

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.

Is it possible to use IB to automatically change the size of items upon rotation?

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.

Resources