pizzafilms
pizzafilms

Reputation: 4019

How to prevent UIImageView from resizing with Autolayout

I'm recreating my UI with auto layout and have a navbar across the top and a 2x2 grid of UIImageViews filling the rest of the screen. I put in all the constraints so it maintains this arrangement in any orientation and it's working well when the UIImageViews don't have an image in them. When I programmatically load an image in the UIImageViews, they change size and placement even though I have constraints that should prevent this.

I have all the autoresizing masks off for everything and the UIImageViews set to Aspect fit.

This autolayout stuff is new to me, but I thought I had it working...until I put an image in there. Why would that change the size and placement of the UIImageViews?

Thanks for the help!

Upvotes: 1

Views: 10659

Answers (1)

Cocoanetics
Cocoanetics

Reputation: 8247

You can modify contraints at runtime if you link them with an outlet in your view controller.

For your case you would add a width and height constraint and link them to two outlets. Then after you know the image dimensions you would change the constant value.

I am describing this in detail for a similar use case I had here: http://www.cocoanetics.com/2012/11/first-good-auto-layout-use-case/

Upvotes: 3

Related Questions