Kody R.
Kody R.

Reputation: 2460

How to correctly use aspect ratio in xcode

So I'm trying to create a user profile that has a user picture that changes sizes with the screen size so it doesn't take up too much space on the smaller iPhone screens.

Everything else in my simulator is sizing correctly during simulation, but the user picture changing size correctly without breaking the ability to stay circular. I tried using aspect ratio, but the picture stays the same size when I simulate on smaller screens. I tried using aspect ratio in relation to the whole view (so that it changes sizes depending on the view), but since the view is rectangular, the picture cannot hold it's ability to stay circular (since it needs to be a square to correctly make the picture circular).

How would I achieve this without creating different views for each phone screen size?

Upvotes: 1

Views: 504

Answers (1)

Glorfindel
Glorfindel

Reputation: 22631

If you set the contentMode of your UIImageView to UIViewContentModeScaleAspectFit, it doesn't matter if the view itself is not square - the image will always show in the right aspect ratio.

Upvotes: 2

Related Questions