Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Mary Kenkel
Mary Kenkel
4,028 Points

The image is distorted

Hello,

When I add the constraints and run the app in the simulator, the image is slightly distorted. The distortion is especially obvious in the image of Saturn. It's elongated, looking more like an egg than a circle.

I've opened the swift file available for download and it looks the same.

I'm guessing that the issue is the screen size of the iPhone XR that I'm running the simulation on that's the problem. It must be a different aspect ratio than the iPhone this was developed for.

But, constraints should be able to deal with different screen sizes, correct?

So, how do I add constraints (programmatically) that will work on all screen sizes?

Mary Kenkel
Mary Kenkel
4,028 Points

Ok, I figured this out.

In case anyone is interested, you can eliminated the image distortion by adding this line of code:

artworkView.contentMode = .scaleAspectFill

Christopher Debove
Christopher Debove
Courses Plus Student 18,371 Points

Yeah you can get rid of the distortion but the image is cropped on the sides.