ioscocoa-touchuiimageviewcontentmode

iOS: How to align (left/right) a UIImageView when using UIViewContentModeScaleAspectFill?


I'm playing with the contentMode property of the UIImageView.

When I set it to UIViewContentModeScaleAspectFill, the image is scaled to fit the screen. It's centered. So right and left (or top and bottom, depending on the screen orientation) part of the picture are clipped.

I'd like to have the same behaviour but not centered. Is that possible to have the image to be clipped only on the right (or left) side? (again top or bottom depending on the orientation) ?

thanks


Solution

  • I know it's been a while since February, but I just encountered the same need in the app I am developing.

    I solved it using a custom UIImageView which can be easily integrated into your existing code (it's a drop-in replacement of UIImageView).

    You can find the class on github, along with an example: https://github.com/reydanro/UIImageViewAligned

    Hope this helps you on your next projects