Reputation: 85
A while ago I thought it might be a good idea to replace my own layout for a number of views inside a scrollview with a UIStackView. But after more than a week of frustration I'm asking for help: I'd like to place subviews like these:
inside a vertical UIStackView (alignment fill, distribution fill). The UIImageView's content mode is aspect fill, the image is set at runtime and can change at runtime (especially its aspect). I'd like the subviews to horizontally fill the stack view and to resize vertically in order to keep the image's aspect ratio intact.
When I don't add any special constraints, I don't get layout warnings, but the subview inside my stack view doesn't resize when I change the image. If I add an aspect constraint to the UIImageView every time the image is being set, I get a layout warning the first time I change the image and afterwards it doesn't resize the subview.
Can someone of you auto layout wizards please help me out?
Upvotes: 1
Views: 2010
Reputation: 3802
You cannot set a constraint on an ImageView
based on an image that will be loaded later. What you should do instead is
ImageView
IBOutlet
to this constraintImageView
's height constraintUpvotes: 2