2
votes

For my Xcode swift project, I would like to keep an image the same size between portrait and landscape. Or at least, not as big in landscape.

The trouble comes from my specific trailing and leading number constraints on the image. I want to keep the image close to the sides of the screen during portrait mode; so the constraints allow it to look neat. However in landscape, the image becomes too big and takes up too much screen real-estate because of these leading/trailing dimensions.

Here is a fairly crude drawing of what I would like to do:

http://i.imgur.com/lYQwOuL.png

EDIT: I would like to preform this on iPhone and iPad devices, so I'm dealing with big screens and small screens. But I would like to keep the portrait width for landscape. Or at least, have my landscape image smaller.

What would be the best way to go about something like this?

  • Maybe center it in container and set the width to some "portrait-screen width" variable?

  • In android, I was able to split an xml into 2 for portrait and landscape. For the landscape version, I set the width of the image to be a fraction of the screen width. Luckily, that process was not a headache.

Any help is definitely appreciated!

2
were you able to resolve it? - Bista

2 Answers

4
votes

Use Aspect-ratio for image :

  1. Remove constraints - trailing space, bottom space
  2. Add Constraints - aspect Ratio , center Horizontally to container.

This will make image uni-formally big in size according to land-space view.

Or you can use fixed Width-Height, but that will make it look same on all devices.

  1. Remove constraints : leading space, trailing space, bottom space
  2. Add constraints : fixed width, fixed height, center horizontally in container
0
votes

You can do simply like that.

  1. Horizontally center view to container view.
  2. keep constant space to top.
  3. keep constant width and height.