Search code examples
iosswiftconstraintsnslayoutconstraintuistackview

UIStackView: Aspect fill image squashed issue


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


Solution

  • 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?