Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build an Interactive Story App with Swift 2 Creating the User Interface Programmatically Creating Views Programmatically

Jordan George
Jordan George
9,926 Points

How does NSLayoutConstraint know what size the artwork should be?

I just figured that we would have to end up resizing the artwork but then was surprised to see it already done.

1 Answer

Drew Carver
Drew Carver
5,189 Points

I believe what's happening is that since the UIImage object is being constrained to all 4 sides of the view, when we load the image into it, it's going to fill that entire area, without stretching the image. Thus it goes fully across the sides and top and doesn't stretch to the bottom (to maintain the aspect ratio of the image).

I couldn't find anything stating this specifically, so if anyone else has any input, feel free to chime in.

Abdulwahab Alansari
Abdulwahab Alansari
15,151 Points

I was asking myself why the image didn't stretch to the bottom of the view.