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 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?

Christopher Debove
Christopher Debove
Courses Plus Student 18,373 Points

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

1 Answer

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