Search code examples
iosxcode-storyboard

How to set image UniformToFill stretch mode


I'm coming from XAML world where we have image stretch mode of Fill, UniformToFill, and Uniform. I'm targeting to achieve UniformToFill mode in my iOS app. In iOS, I came across ScaleToFill, AspectToFit, AspectToFill, and many others. None of them fulfill my requirement.

Required behavior: UIImageView (image container) size in layout remains fixed. Scale image according to fixed size of UIImageView and maintain aspect ratio of image itself. Upon matching either of side (vertical, horizontal), clip rest of the image.

To illustrate it better, here's the screenshot; I'm looking to achieve third from left.

Image stretch mode


Solution

  • XAML to iOS conversion is as follows.

    Fill = ScaleToFill

    Uniform = AspectToFit &

    UniformToFill = AspectToFill

    This is the exact match. If you are not getting this result, then it means you have done mistake in something else. Otherwise, this is perfect matching.