How to properly add an UIImageView inside an UIStackView

Adrian picture Adrian · Aug 15, 2015 · Viewed 11.3k times · Source

My UIImageView is loaded with a picture with a high resolution. When I add the UIImageView to the UIStackView, the stack view will grow up to 1900x1200 dimension. The UIImageView contentMode is set to Aspect Fill.

What can I do so that the image remains with its current dimension (130x130) after adding it to the stack view ?

Answer

Rob Norback picture Rob Norback · Sep 28, 2015

I hope you got your question answered by now, but if not here you go:

Simply add a height and width constraint to your UIImageView before putting it in your stack view. Make them both 130 and you should be good to go.