Sweeper
Sweeper

Reputation: 270820

How to configure the image or image view so that the image keeps its aspect ratio no matter what the size of the image view is?

I put an image view in a static table view cell. The image is now being stretched to fit the whole view. I want the image to:

First I went to the docs of UIImageView. But didn't find anything useful. Then I looked at the docs of UIImage and found UIImageResizingMode. But that enum only contains Stretch and Tile, which is not what I wanted. I then found this post which told me to

logo.contentMode = .Center

But the image is still stretched. I then tried this

logo.contentMode = .ScaleAspectFill

But the result is the same.

Please tell me a good way to do this!

Additional info:

The image view has the following constraints:

enter image description here

Upvotes: 1

Views: 60

Answers (1)

Matt39
Matt39

Reputation: 149

You have to set the contentMode to UIViewContentModeScaleAspectFit.

Upvotes: 1

Related Questions