0
votes

I want this to work on all iPhones from 4 to 6+ portrait only.

Look at this autolayout designed for iPhone 4:

enter image description here

This imageView has an aspect ratio of 49:59 and has to keep this constant.

The imageView is inside a UIView container (the orange box). The orange container is attached to the 4 corners with 0 space. On the bottom part of the interface, another container (the white one) that contains 4 sliders.

This is the constraints I have applied to that imageView: top, bottom, leading, trailing to the orange container and aspect ratio 49:59.

This is how it scales to other iPhone screens:

enter image description here

but I don't want that. Look of how much screen is wasted on bigger iPhones.

What I want is the imageView to scale until it touches the left and right borders.

I want this:

enter image description here

There is plenty room for the view to scale and touch the left and right borders on big iphones while still keeping the same aspect ratio.

What kind of constraints should I apply to the imageView to do that? I have tried everything.

2
What constant values do you have for the leading and trailing constraints between the image view and the orange view? - rdelmar
38 and 37 but I have tried to change that to >= 0 but the image expands to bigger than the screen. - Duck

2 Answers

1
votes

I haven't tried this, but I think it should work, if you give the image view constraints to the left and right sides of the orange view with constant values of 0 (or some other small number if you want a little orange showing), a centerY constraint, and the aspect ratio constraint.

0
votes

After hours of fighting I got it to work. The constraints to the imageView are:

centerX, centerY, trailing and leading both >= 0, top and bottom both >= 3 and aspect ratio locked to 49:59.

This auto layout thing is the opposite of something intuitive.