Difference between UIViewContentModeScaleAspectFit and UIViewContentModeScaleToFill?
Asked Answered
C

3

159

what is the difference between UIViewContentModeScaleAspectFit and UIViewContentModeScaleToFill...?

Coronograph answered 4/2, 2011 at 6:43 Comment(0)
W
191

If you are talking about UIViewContentMode, the following is from the Doc.

UIViewContentModeScaleToFill

Scales the content to fit the size of itself by changing the aspect ratio of the content if necessary.

UIViewContentModeScaleAspectFit

Scales the content to fit the size of the view by maintaining the aspect ratio. Any remaining area of the view’s bounds is transparent.

UIViewContentModeScaleAspectFill

Scales the content to fill the size of the view. Some portion of the content may be clipped to fill the view’s bounds.

Wagonette answered 4/2, 2011 at 6:51 Comment(2)
What is an example of where transparency or clipping would occur? I am picturing a rectangle and it seems as if that clause would never be invoked.Theoretical
Praxiteles, I am not quite understand your question. But from the context of my answer above, clipping will possibly occur in UIViewContentModeScaleToFill & UIViewContentModeScaleAspectFill, if the image ratio does not match the imageView's ratio. Please correct me if I have mistaken your question. Thanks.Wagonette
I
582

You can see the differences between the content modes here:

enter image description here

Redraw mode works as Scale to Fill mode. But there is a difference in how they are drawn when view geometry changes. Scale to Fill mode uses already rendered content while Redraw mode renders the content again.

Intentional answered 10/7, 2014 at 7:42 Comment(0)
W
191

If you are talking about UIViewContentMode, the following is from the Doc.

UIViewContentModeScaleToFill

Scales the content to fit the size of itself by changing the aspect ratio of the content if necessary.

UIViewContentModeScaleAspectFit

Scales the content to fit the size of the view by maintaining the aspect ratio. Any remaining area of the view’s bounds is transparent.

UIViewContentModeScaleAspectFill

Scales the content to fill the size of the view. Some portion of the content may be clipped to fill the view’s bounds.

Wagonette answered 4/2, 2011 at 6:51 Comment(2)
What is an example of where transparency or clipping would occur? I am picturing a rectangle and it seems as if that clause would never be invoked.Theoretical
Praxiteles, I am not quite understand your question. But from the context of my answer above, clipping will possibly occur in UIViewContentModeScaleToFill & UIViewContentModeScaleAspectFill, if the image ratio does not match the imageView's ratio. Please correct me if I have mistaken your question. Thanks.Wagonette
C
132

uiimageview-scaling-explained-visually

enter image description here

Combe answered 24/10, 2014 at 11:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.