1

I have 4 images inside a UIStackView which is constrained 20pts from top, right, bottom, left.

4 images are set to Aspect Fit and the UIStackView settings are set to: Fill Equally, and Spacing of 20.

When I come to view this on an iPhone 8 upwards the layout works. When viewing on an iPhone SE layout I get squashing of the images as below.

Shouldn't the fact that Aspect Fit has been set solve this issue and scale the image down accordingly?

Initial constraint values

View showing on smaller devices

Thanks

Fogmeister
  • 76,236
  • 42
  • 207
  • 306
user7684436
  • 697
  • 14
  • 39

1 Answers1

2

Add an aspect ratio constraint to each image and set it to 1:1. This should make the images have the same height and width, no matter the width of the screen.

I agree however, that using "aspect fit" should work. Are these regular images stored in your app bundle, or are you creating them with code or something similar?

rodskagg
  • 3,827
  • 4
  • 27
  • 46
  • I've tried both approaches, the current is a pdf image – user7684436 May 18 '18 at 09:29
  • What sizes are the UIImageViews when you run your app? If you click the "Debug view hierarchy" in XCode while running the app, what constraints do you have, and what are their values? – rodskagg May 18 '18 at 09:41
  • Adding in the ratio suggestion along with setting the content hugging to 749 and a trailing constraint worked on all screen sizes. I'll have to remove the constraint on SE layouts but thats a minor niggle. Thanks for your help. – user7684436 May 18 '18 at 09:44
  • @user7684436 you shouldn't have to change constraints or specific devices at all. You have found a workaround for the problem here... you haven't fixed it. – Fogmeister May 18 '18 at 09:54
  • Well I know I shouldn't but with Xcode being the great piece of software it is - I had to. – user7684436 May 18 '18 at 13:11